Add solutions for problem 31

This commit is contained in:
2019-09-20 15:12:47 +02:00
parent e8f5980a55
commit cadb92b671
3 changed files with 88 additions and 2 deletions

View File

@ -1,7 +1,5 @@
#!/usr/bin/python3
from numpy import zeros
from timeit import default_timer
def main():

33
Python/p031.py Normal file
View 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()