Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Solved 31, but I think I can clean it up some

commit acb757daf16a02b5326b24094409597a22063bbf 1 parent 053c2c1
@coleifer authored
Showing with 19 additions and 4 deletions.
  1. +19 −4 problem31.py
View
23 problem31.py
@@ -1,6 +1,21 @@
-# 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
-coins = [1, 2, 5, 10, 20, 50, 100, 200]
-
+coins = [200, 100, 50, 20, 10, 5, 2, 1]
goal = 200
-# recursion?
+def chase(coins, goal):
+ total = 0
+ x = goal / coins[0]
+
+ new_coins = coins[1:]
+
+ if len(new_coins):
+ for i in range(x, -1, -1):
+ new_goal = goal - (i * coins[0])
+ if new_goal == 0:
+ total += 1
+ else:
+ total += chase(new_coins, new_goal)
+ else:
+ total = 1
+ return total
+
+print chase(coins, goal)
Please sign in to comment.
Something went wrong with that request. Please try again.