/
count_the_coins_solution.py
53 lines (43 loc) · 1.32 KB
/
count_the_coins_solution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
import sys
import Student as student
def main(argv):
test1 = [100, [1, 5, 10, 25]]
test2 = [200, [1, 5, 10, 25]]
isCorrect = True
# student = problemSet.Correct()
test1_correct = str(correct_changes(test1[0], test1[1]))
test1_student = str(student.changes(test1[0], test1[1]))
print "Correct Output: " + test1_correct
print "Your Output: " + test1_student
if compare(test1_correct, test1_student):
print "Correct!"
else:
print "Incorrect"
isCorrect = False
test2_correct = str(correct_changes(test2[0], test2[1]))
test2_student = str(student.changes(test2[0], test2[1]))
print "Correct Output: " + test2_correct
print "Your Output: " + test2_student
if compare(test2_correct, test2_student):
print "Correct!"
else:
print "Incorrect"
isCorrect = False
def compare(arr1, arr2):
i = 0;
if len(arr1) != len(arr2):
return False
for i in range(0, len(arr1)):
if arr1[i] != arr2[i]:
return False
return True
def correct_changes(amount, coins):
ways = [0] * (amount + 1)
ways[0] = 1
for coin in coins:
for j in xrange(coin, amount + 1):
ways[j] += ways[j - coin]
return ways[amount]
if __name__ == "__main__":
main(sys.argv[1:])