After paying for a newspaper with 4 quarters, the newspaper came out. But, to my surprise, my 4 quarters also came back out because the machine was broken. I quickly took note of how I paid for the paper: "4 quarters." After spending over a quarter of an hour at the machine, I paid for a newspaper in every possible way.
How many newspapers did I end up with?
Assumptions:
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.
Why is there a + 1 in the first sum? I am guessing it has something to to with the option where the pennies are used to fill up the rest of the missing coins, but I am not sure
Log in to reply
I don't quite remember. I think it is to account for the case when 5 1 0 0 − 2 5 q − 1 0 d = 0 . Look at the table given by Jeremy Galvagni below. When q = 4 , then d = 0 and 5 1 0 0 − 2 5 q − 1 0 d = 0 but there is 1 count. I actually did a table similar to that of Jeremy from which I derived the formula to make sure that the formula is correct. You can also check it against Jeremy's table.
When expanding the inner sum, if you substitute q = 1, you get 7.5 in the expression at the top of the summation, not 7.
I assume that you can use 7 here instead of 7.5 because the term on top of the summation can be rounded down. Is this a general rule, or just applicable in this scenario? Either way, this is not intuitive to me - anyone care to offer an explanation?
Log in to reply
⌊ ⋅ ⌋ denotes the floor function also known as the greatest integer function. For example ⌊ 3 . 0 1 ⌋ = 3 , ⌊ 7 . 9 9 9 ⌋ = 7 , ⌊ 8 ⌋ = 8 .
Log in to reply
Oh thanks! Silly me - I read that in the description but somehow thought they were square parenthesis in the equality!
Log in to reply
@P M – I added in the description after you have commented. Parenthesis is not necessary there. I won't key in unnessary keystrokes.
I don't get it, isn't the machine broken?
Log in to reply
The point is, the character was supposed to attempt to buy a newspaper with all combinations of quarters, nickels, pennies and dimes that make a dollar, to see if the machine works for only certain combinations thereof.
Log in to reply
But it was a little bit confusing for me cause the problem didn't especify if diferent order of putting the coins into the maschine matters.
what type of man carries a minimum of 100 pennies 10 dimes,20 nickels and 4 quarters? Take the free paper and go home! and I have Never seen a paper machine that takes pennies( which are no longer used in progressive societies like Canada)
Log in to reply
A man who lives in the world of Math Fantasia. I share your same frustration. Read my article .
Q | D | N | count |
4 | 0 | 0 | 1 |
3 | 2 | 1 | 2 |
3 | 1 | 3 | 4 |
3 | 0 | 5 | 6 |
2 | 5 | 0 | 1 |
2 | 4 | 2 | 3 |
2 | 3 | 4 | 5 |
2 | 2 | 6 | 7 |
2 | 1 | 8 | 9 |
2 | 0 | 10 | 11 |
1 | 7 | 1 | 2 |
1 | 6 | 3 | 4 |
1 | 5 | 5 | 6 |
1 | 4 | 7 | 8 |
1 | 3 | 9 | 10 |
1 | 2 | 11 | 12 |
1 | 1 | 13 | 14 |
1 | 0 | 15 | 16 |
0 | 10 | 0 | 1 |
0 | 9 | 2 | 3 |
0 | 8 | 4 | 5 |
0 | 7 | 6 | 7 |
0 | 6 | 8 | 9 |
0 | 5 | 10 | 11 |
0 | 4 | 12 | 13 |
0 | 3 | 14 | 15 |
0 | 2 | 16 | 17 |
0 | 1 | 18 | 19 |
0 | 0 | 20 | 21 |
The 'count' column is merely nickels+1 because you can replace any amount of n nickels with 5 pennies in n+1 ways.
The sum of the 'count' column is 2 4 2 . You can add the numbers with clever tricks because there are simple sequences of even or odd numbers.
Interesting! You used brute force and math in a surprising way!
Log in to reply
I actually didn't write this all out on paper when I first solved it, but I wanted to show the whole thing here.
why we dont think about order
Log in to reply
Good question. The problem doesn't specify, but we seem to have assumed order of coins doesn't matter.
I suppose one could argue that if we did consider order, it would take way more than 15 minutes to use them all. (242 is already hard to believe as we'd be doing a different combination more than once every 4 seconds.) The number of combinations explodes once you realize many of the above use lots of pennies.
Sort the cases by the number of pennies used. Since a nickel, a dime and a quarter are all multiples of $0.05, we have that in order to obtain a total of $1.00, a multiple of $0.05 itself, the number of pennies must be divisible by 5.
This means that we can instead consider the number of ways in which $0.00, $0.05, $0.10, ..., $0.95, $1.00 can be made up of nickels, dimes and quarters. Dividing both sides by $0.05 gives us that we can alternatively look at the number of ways in which every number from 0 to 2 0 can be represented as a sum of 1 's, 2 's and 5 's.
Label the number of ways k can be represented as a sum of 1 's, 2 's and 5 's as N ( k ) . Notice that N ( k − 5 ) counts the number of such representations that contain at least one 5 (one way to think about this: given that a representation contains a 5 , one can simply write down the number and then choose the other summands for which there are N ( k − 5 ) ways by definition). Similarly, N ( k − 2 ) counts the number of such representations that contain at least one 2 . Notice further that N ( k − 7 ) counts the number of such representations that contain a 5 and a 2 . Hence the number of representations that contain any 5 's or 2 's is given by N ( k − 2 ) + N ( k − 5 ) − N ( k − 7 ) However, there is only one representation for k which contains no 5 's or 2 's: namely the one consisting of k 1 's. So we obtain the recurrence relation N ( k ) = N ( k − 2 ) + N ( k − 5 ) − N ( k − 7 ) + 1 Solving by hand yields
From here one could either try to solve the difference equation with the given initial conditions (which would include solving a 7th degree polynomial) or just repeatedly apply the recurrence relation to obtain the values of N ( k ) for 7 ≤ k ≤ 2 0 . Adding all these to the above ones yields the answer 2 4 2 .
The way we will choose our coin combination will be by choosing the number of quarters, then the number of dimes, then nickels, then filling in the remainder with pennies.
# of quarters | remaining cost | max # of dimes |
0 | 100 | 10 |
1 | 75 | 7 |
2 | 50 | 5 |
3 | 25 | 2 |
4 | 0 | 0 |
For now, let's only consider the coin combinations with 0 quarters:
For the combinations with 0 dimes, there are 2 1 possible combinations, as there can be any number of nickels between 0 and 2 0 inclusive.
For every extra dime, there will be 2 fewer possible combinations, as we will only be able to use up to so many nickels.
This means the number of combinations with 0 quarters is 2 1 + 1 9 + 1 7 + . . . + 3 + 1 . Following the same logic with the others:
# of quarters | max # of nickels | # of combinations |
0 | 20 | 2 1 + 1 9 + 1 7 + . . . + 3 + 1 |
1 | 15 | 1 6 + 1 4 + 1 3 + . . . + 4 + 2 |
2 | 10 | 1 1 + 9 + 7 + 5 + 3 + 1 |
3 | 5 | 6 + 4 + 2 |
4 | 0 | 1 |
From here, we can use the formula for triangle numbers 2 n ( n + 1 ) to quickly find the total:
For 1 and 3 quarters, we would need 2 × 2 8 ( 8 + 1 ) and 2 × 2 3 ( 3 + 1 ) respectively. (Consider 6 + 4 + 2 = 2 × ( 3 + 2 + 1 ) .)
For 0 and 2 quarters, we need the slightly more complicated ( 2 2 1 × 2 2 ) − ( 2 × 2 1 0 × 1 1 ) and ( 2 1 1 × 1 2 ) − ( 2 × 2 5 × 6 ) . This gives us:
1 2 1 + 7 2 + 3 6 + 1 2 + 1 = 2 4 2
We wish to find the coefficient of the x 1 0 0 in the expansion of the generating function ( 1 − x 1 ) ( 1 − x 5 1 ) ( 1 − x 1 0 1 ) ( 1 − x 2 5 1 ) . Here x is a placeholder variable whose exponent represents an additive value (such as amount of money) and whose coefficient represents the number of combinations. With a computational tool this can be computed as 2 4 2 .
Find coefficient of x^100 = 242 in expansion of product of generating function
{1/(1-x)}{1/(1-x^5)}{1/(1-x^10)}{1/(1-x^25)},
Used WolframAlpha Script
SeriesCoefficient[1/(1 - x)×1/(1 - x^5)×1/(1 - x^10)×1/(1 - x^25), {x, 0, 100}]
Answer=242
Read the following pdf/link for details, hope it helps,
https://arxiv.org/pdf/1406.5213
https://arxiv.org/abs/1406.5213
Another Method
Find number of non-negative solutions (w,x,y,z) to the following Diophantine equation:
w+5x+10y+25z=100.
Python3 program can be written to solve this equation as below:
import array as a
a=a.array('i',[1, 5, 10, 25])
n=100
def diophantine_count(a,n):
"""Computes the number of nonnegative solutions (x) of the linear
Diophantine equation
a[0] * x[0] + ... a[N-1] * x[N-1] = n
Theory: For natural numbers a[0], a[2], ..., a[N - 1], n, and j,
let p(a, n, j) be the number of nonnegative solutions.
Then one has:
p(a, m, j) = sum p(a[1:], m - k * a[0], j - 1), where the sum is taken
over 0 <= k <= floor(m // a[0])
Examples
--------
>>> diophantine_count([3, 2, 1, 1], 47)
3572
>>> diophantine_count([3, 2, 1, 1], 40)
2282
"""
def p(a, m, j):
if j == 0:
return int(m == 0)
else:
return sum([p(a[1:], m - k * a[0], j - 1)
for k in range(1 + m // a[0])])
return p(a, n, len(a))
print(diophantine_count(a,n))
Answer=242
Okay, this is correct, but why is it correct?
Log in to reply
Read the following pdf/link for details, hope it helps,
https://arxiv.org/pdf/1406.5213
https://arxiv.org/abs/1406.5213
Log in to reply
Was kinda hoping for an original explanation, but this works too. More detail than anyone could've ever provided; thanks!
Using Wolfram Mathematica 11..3.
Yes, this could have done in other languages. that support recursion, big integers and memoization of previously computed answer.
Another example of this class of problem: How many ways of making change for a $1000 banknote, including just returning the input, and using combinations of $500, $100, $50, $20, $10, $5, $2, $1, $0.50, $0.25, $0.10, $0.05 and $0.01 bills or coins.
Problem Loading...
Note Loading...
Set Loading...
Let the numbers of quarters, dimes, nickels and pennies need to make up 1 dollar or 100 cents be q , d , n , and p respectively. Then we have 2 5 q + 1 0 d + 5 n + p = 1 0 0 . And note that q can have 5 values from 0 to 4. For a q , d can take the value from 0 to ⌊ 1 0 1 0 0 − 2 5 q ⌋ , where ⌊ ⋅ ⌋ denotes the floor function . For a q and a d , n can take the value from 0 to 5 1 0 0 − 2 5 q − 1 0 d . For a q , a d , and a n , there can be only 1 value of p . Therefore, to find the total number of ways to pay with the four kinds of coin N , we need only to calculate the total number of combinations of ( q , d , n ) .
N = q = 0 ∑ 4 d = 0 ∑ ⌊ 1 0 1 0 0 − 2 5 q ⌋ ( 5 1 0 0 − 2 5 q − 1 0 d + 1 ) = q = 0 ∑ 4 d = 0 ∑ ⌊ 1 0 − 2 . 5 q ⌋ ( 2 1 − 5 q − 2 d ) = q = 0 d = 0 ∑ 1 0 ( 2 1 − 2 d ) + q = 1 d = 0 ∑ 7 ( 1 6 − 2 d ) + q = 2 d = 0 ∑ 5 ( 1 1 − 2 d ) + q = 3 d = 0 ∑ 2 ( 6 − 2 d ) + q = 4 d = 0 ∑ 0 ( 1 − 2 d ) = 2 3 1 − 1 1 0 + 1 2 8 − 5 6 + 6 6 − 3 0 + 1 8 − 6 + 1 − 0 = 2 4 2