Created
March 20, 2018 10:29
-
-
Save jacksonfdam/757c6e90f204b6ee2ed065a1dc129fa9 to your computer and use it in GitHub Desktop.
Baseado em uma resposta a uma questão que fiz no Yahoo! Respostas.
This file contains 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 moedas = [0.01, 0.05, 0.10, 0.25, 0.50, 1.00, 2.00, 5.00, 10.00, 20.00, 50.00, 100.00]; | |
var valor = 4.10 ; | |
function modos(troco,maior_moeda){ | |
if(maior_moeda < 0){ | |
return 1; | |
} | |
var contador = 0; | |
while(troco >= 0 ){ | |
contador = contador + modos(troco, maior_moeda -1); | |
troco = troco - moedas[maior_moeda]; | |
} | |
return contador; | |
} | |
console.log(modos(valor,12)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment