Skip to content

Instantly share code, notes, and snippets.

@jacksonfdam
Created March 20, 2018 10:29
Show Gist options
  • Save jacksonfdam/757c6e90f204b6ee2ed065a1dc129fa9 to your computer and use it in GitHub Desktop.
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.
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