Skip to content

Instantly share code, notes, and snippets.

@germanescobar
Created November 27, 2021 00:16
Show Gist options
  • Save germanescobar/d05497451560b8172364fb3538fed8ff to your computer and use it in GitHub Desktop.
Save germanescobar/d05497451560b8172364fb3538fed8ff to your computer and use it in GitHub Desktop.
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
}
@germanescobar
Copy link
Author

No funciona con este caso: "27346209830709182346"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment