Created
June 8, 2012 00:20
-
-
Save kristenmills/2892581 to your computer and use it in GitHub Desktop.
Project Euler 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
def solve | |
coins = [1, 2, 5, 10, 20, 50, 100, 200] | |
goal = 200 | |
ways = Array.new | |
ways << 1 | |
200.times do | |
ways << 0 | |
end | |
coins.each do |coin| | |
coin.upto(goal) do |x| | |
ways[x] += ways[x-coin] | |
end | |
end | |
return ways[goal] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment