Created
November 27, 2021 00:16
-
-
Save germanescobar/d05497451560b8172364fb3538fed8ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var minPartitions = function(n) { | |
const decibinary = calculateDecibinary(n) | |
const res = parseInt(n, 10) - parseInt(decibinary, 10) | |
console.log(n, decibinary, res) | |
if (res === 0) return 1 | |
return 1 + minPartitions(res.toString()) | |
}; | |
function calculateDecibinary(n) { | |
let result = "" | |
for (let i=0; i < n.length; i++) { | |
if (n[i] !== "0") { | |
result += "1" | |
} else { | |
result += "0" | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No funciona con este caso: "27346209830709182346"