Created
July 30, 2013 17:44
-
-
Save tomca32/6115134 to your computer and use it in GitHub Desktop.
Coin sums problem recursively in JS
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
; | |
//Project Euler Problem #4 - Largest Palindrome Product | |
(function (exports) { | |
"use strict"; | |
var coins = [1,2,5,10,20,50,100,200]; | |
exports.change = function (money,i) { | |
if (money === 1 || money ===0) return 1; | |
if (i <0) return 0; | |
if (typeof i ==='undefined') i = coins.length-1; | |
if (coins[i] > money) return exports.change(money, i-1); | |
// console.log(money, i); | |
return exports.change(money-coins[i], i) + exports.change(money, i-1); | |
}; | |
}(global)); | |
console.log(change(200)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment