In Brilliantown the currency is the brill ( B .) There are four denominations in use : 1 B , 7 B , 2 3 B and 5 9 B banknotes.
How many ways are there to pay for 4 4 2 B ?
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
3703517 iteration, seems like lots of computation there.
RationalQ = Simplify [ $#$1 ∈ Q ] & ;
change ( amount$_$ /; RationalQ ( amount ) ∧ amount ≥ 0 , currency$__$ /; Head [ currency ] = List ∧ AllTrue [ currency , RationalQ ] ∧ AllTrue [ currency , Positive ] ) := Block [ { c , a , s } , c ( 0 , _ ) := 1 ; c ( a$_$ , _ ) := 0 /; a < 0 ; c ( a$_$ , { } ) := 0 /; a = 0 ; c ( a$_$ , s$_$ ) := c ( a , s ) = c ( a − First [ s ] , s ) + c ( a , Rest [ s ] ) ; c ( amount , Sort [ Union [ currency ] , Greater ] ) ] ;
change ( 4 4 2 , { 5 9 , 2 3 , 7 , 1 } ) ⟹ 2 0 1 8
a = 0 ∑ 7 b = 0 ∑ ⌊ 2 3 1 ( 4 4 2 − 5 9 a ) ⌋ ( 1 + ⌊ 7 1 ( 4 4 2 − 5 9 a − 2 3 b ) ⌋ ) = 2 0 1 8 counts the number of ways of paying with a × 5 9 B , b × 2 3 B , c × 7 B , with the rest in singles.
How did you compute the sum?
Log in to reply
It can be computed by using two for loops. Actually, I think this approach works well for 4 kinds of banknotes. A
Log in to reply
For this coin change problem, an alternative solution could be using dynamic programming.
Can you elaborate, how did you arrive at this sum?
Problem Loading...
Note Loading...
Set Loading...
We could consider all the ways to evaluate 4 4 2 using { 1 , 7 , 2 3 , 5 9 } like
a + b ⋅ 7 + c ⋅ 2 3 + d ⋅ 5 9 = 4 4 2
where
0 ≤ a ≤ ⌊ 1 4 4 2 ⌋ = 4 4 2
0 ≤ b ≤ ⌊ 7 4 4 2 ⌋ = 6 3
0 ≤ c ≤ ⌊ 2 3 4 4 2 ⌋ = 1 9
0 ≤ d ≤ ⌊ 5 9 4 4 2 ⌋ = 7 .
The right-side bound is the biggest coefficient such that I can multiplay a , b , c or d before finding a number greater than 4 4 2 . Let's use a simple MATLAB code to evaluate all the possible occurrences: