With all the new crypto currencies coming out I think it's time we make our own currency. Since we have such a great community and marketing team our currency really takes off and becomes the official currency of a small large nation. The denominations of our currency are as such:
[0.03, .08, .33, .5, 2, 10, 50, 100]
If someone comes to our store and asks for change for a $10 note. How many different ways can we offer change for the $10 note assuming with have an infinite amount of all denominations of our currency?
Comments:
Foppe - 10 years, 9 months ago
reply permalink
Foppe - 10 years, 9 months ago
The range function is not inclusive so you need to add 1 to everyone of this. The final grand total is 8937
reply permalink
Max Burstein - 10 years, 9 months ago
Definitely an interesting solution. Good stuff
reply permalink
vick - 10 years, 9 months ago
I've found a small typo in line "for j in range(120):"
I think, it should be "for j in range(125 + 1):", since 10 / 0.08 = 125
Thus, grand total is 8939.
Thank you for the nice solution!
reply permalink
Foppe - 10 years, 9 months ago
The difference with the Haskell solution is due to rounding errors. When using integers I get the correct result 8954 with $10 <-> $10. Also I thought this would speed up a littlebit. #! /usr/bin/python
reply permalink
Foppe - 10 years, 9 months ago
Optimization: By adding lines like for k in range(31): kk = k * v[2] if ii + jj + kk > 1000: # <- Added break # <- Added in all for loops this speeds up to $ time python change.py 8954
That's from 7 minutes to 10 seconds.
reply permalink
Foppe - 10 years, 9 months ago
Formatted: for k in range(31): kk = k * v[2] if ii + jj + kk > 1000: # <- Added break # <- Added
reply permalink
Anonymous - 10 years, 9 months ago
Awesome stuff man.
reply permalink
Max! - 10 years, 9 months ago
In Wolfram Alpha : power series (1/((1-x^3)(1-x^8)(1-x^33)(1-x^50)(1-x^200)(1-x^1000)))
Then expand terms till the 1000th coefficient and I see 8954 ways. Is my combinatorial equation incorrect? I wanted to find the right solution before trying to code it up.
reply permalink
Apanatshka - 10 years, 9 months ago
That sounds about correct. My program gives back 8953, because I filtered the solution where you give back the $10 note as change.
reply permalink
Apanatshka - 10 years, 9 months ago
Haskell implementation, not as trivial as I expected:
It prints 8953. If you write
main = print $ fst answer
you get the different ways in stead of the count.reply permalink
btgrant - 10 years, 8 months ago
Using integers like the Haskel submission, here's a solution in Scala:
reply permalink