Created
January 31, 2013 00:45
-
-
Save chadbrewbaker/4678863 to your computer and use it in GitHub Desktop.
Solution for Sedgewick Analytic Combinatorics homework 1
http://ac.cs.princeton.edu/lectures/AC01-OGFs.pdf
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
#Solution for Sedgewick Analytic Combinatorics homework 1 | |
#http://ac.cs.princeton.edu/lectures/AC01-OGFs.pdf | |
#Chad Brewbaker | |
#crb002@gmail.com | Software Engineer @ Telligen | |
#January 30, 2013 | |
best =0 | |
coins=*(1..100) | |
coins.combination(4).each{ |currency| | |
memo = [0]*100 | |
(0..99).each{ |i| | |
currency.each{ |c| | |
if((i+1)== c) | |
memo[i] = memo[i]+1 | |
else | |
if((i+1-c) > 0 ) | |
memo[i] = memo[i]+memo[(i-c)] | |
end | |
end | |
} | |
} | |
if (memo[-1] >= best) | |
print [currency,memo].inspect + "\n" | |
best = memo[-1] | |
end | |
} | |
# Answer is coin values [1,2,3,4] which produces the Fibbonacci numbers http://oeis.org/A000045 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment