Skip to content

Commit 38241a3

Browse files
author
Steven Landau
committed
Added challenge 17
1 parent c7033a1 commit 38241a3

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

challenge_17/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Change
2+
======
3+
Idea
4+
-----
5+
How many ways can you divide 1000 cents into quarters, dimes, nickles and pennies? We're about to find out. Your job today is to create a program which takes an integer from standard input and determines the number of ways that number can be achieved, using the change listed above.
6+
7+
For example, how many ways could we make 100 cents?
8+
* 4 Quarters
9+
* 2 Quarters, 5 Dimes
10+
* 100 Pennies
11+
* ...
12+
13+
You must output the number of ways in which change can be given for the input.
14+
15+
Testing
16+
-----
17+
100 cents would yield 64207 possible combinations
18+
19+
50 cents would yield 309 possible combinations
20+
21+
150 cents would yield 13322380 possible combinations
22+
23+
I would give more examples but I did it the O(N!) way so it's physically impossible to compute the number of ways to achieve 1000 cents before the universe implodes.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
times = 0
3+
def change(total, p, n, d, q):
4+
global times
5+
sum = p + n + d + q
6+
if sum == total:
7+
#print("q:{} d:{} n:{} p:{}".format(q // 25, d // 10, n // 5, p))
8+
times += 1
9+
return
10+
elif sum > total:
11+
return
12+
else:
13+
change(total, p, n, d, q + 25)
14+
change(total, p, n, d + 10, q)
15+
change(total, p, n + 5, d, q)
16+
change(total, total - q - n - d, n, d, q) # should only have max of 1 depth
17+
18+
change(150, 0, 0, 0, 0)
19+
print(times)

0 commit comments

Comments
 (0)