Add solutions for problem 31
This commit is contained in:
@ -1,7 +1,5 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from numpy import zeros
|
||||
|
||||
from timeit import default_timer
|
||||
|
||||
def main():
|
||||
|
33
Python/p031.py
Normal file
33
Python/p031.py
Normal file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from timeit import default_timer
|
||||
|
||||
def count(coins, value, n, i):
|
||||
for j in range(i, 8):
|
||||
value = value + coins[j]
|
||||
if value == 200:
|
||||
return n + 1
|
||||
elif value > 200:
|
||||
return n
|
||||
else:
|
||||
n = count(coins, value, n, j)
|
||||
value = value - coins[j]
|
||||
|
||||
return n
|
||||
|
||||
def main():
|
||||
start = default_timer()
|
||||
|
||||
coins = [1, 2, 5, 10, 20, 50, 100, 200]
|
||||
|
||||
n = count(coins, 0, 0, 0)
|
||||
|
||||
end = default_timer()
|
||||
|
||||
print('Project Euler, Problem 30')
|
||||
print('Answer: {}'.format(n))
|
||||
|
||||
print('Elapsed time: {:.9f} seconds'.format(end - start))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user