...counted!
You will pass your program a variable which represents a quantity of money in dollars and/or cents and an array of coin values. Your challenge is to output the number of possible combinations of the given array of coin values that would add up to the amount passed to the code. If it is not possible with the coins named, the program should return 0
.
Note on American numismatic terminology:
- 1-cent coin: penny
- 5-cent coin: nickel
- 10-cent coin: dime
- 25-cent coin: quarter (quarter dollar)
Example 1:
Program is passed:
12, [1, 5, 10]
(12 cents)
Output:
4
There are 4 possible ways of combining the coins named to produce 12 cents:
- 12 pennies
- 1 nickel and 7 pennies
- 2 nickels and 2 pennies
- 1 dime and 2 pennies
Example 2:
Program is passed:
26, [1, 5, 10, 25]
(26 cents)
Output:
13
There are 13 possible ways of combining the coins named to produce 26 cents:
- 26 pennies
- 21 pennies and 1 nickel
- 16 pennies and 2 nickels
- 11 pennies and 3 nickels
- 6 pennies and 4 nickels
- 1 penny and 5 nickels
- 16 pennies and 1 dime
- 6 pennies and 2 dimes
- 11 pennies, 1 dime, and 1 nickel
- 6 pennies, 1 dime, and 2 nickels
- 1 penny, 1 dime, and 3 nickels
- 1 penny, 2 dimes, and 1 nickel
- 1 quarter and 1 penny
Example 3:
Program is passed:
19, [2, 7, 12]
Output:
2
There are 2 possible ways of combining the coins named to produce 19 cents:
- 1 12-cent coin and 1 7-cent coin
- 1 7-cent coin and 6 2-cent coins
Example 4:
Program is passed:
13, [2, 8, 25]
Output:
0
There are no possible ways of combining the coins named to produce 13 cents.
This has been through the Sandbox. Standard loopholes apply. This is code golf, so the answer with the fewest bytes wins.
s/count/earn
. \$\endgroup\$