Last active
August 6, 2016 21:21
-
-
Save laltin/0ac5ef9ad84c6c0d62da75d375f8ea28 to your computer and use it in GitHub Desktop.
Solution to Project Euler problem 31
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
<html> | |
<head> | |
<head> | |
<body> | |
<script> | |
var coins = [1, 2, 5, 10, 20, 50, 100, 200]; | |
function ways(x, limit=0) { | |
if (x < 0) { | |
return 0; | |
} | |
if (x == 0) { | |
return 1; | |
} | |
var n = 0; | |
for (var i = 0; i < coins.length; i++) { | |
if (coins[i] <= limit) | |
continue; | |
for (var j = x - coins[i]; j >= 0; j -= coins[i]) { | |
n += ways(j, coins[i]); | |
}; | |
} | |
return n; | |
} | |
document.writeln(ways(200)); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment