Add more python solutions

Added python solutions for problems 19 and 20
This commit is contained in:
daniele 2019-09-19 21:43:55 +02:00
parent eedc0d1271
commit 606cf399b9
Signed by: fuxino
GPG Key ID: 6FE25B4A3EE16FDA
2 changed files with 50 additions and 0 deletions

25
Python/p019.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/python3
import datetime
from timeit import default_timer
def main():
start = default_timer()
count = 0
for year in range(1901, 2001):
for month in range(1, 13):
if datetime.datetime(year, month, 1).weekday() == 6:
count = count + 1
end = default_timer()
print('Project Euler, Problem 19')
print('Answer: {}'.format(count))
print('Elapsed time: {:.9f} seconds'.format(end - start))
if __name__ == '__main__':
main()

25
Python/p020.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/python3
from math import factorial
from timeit import default_timer
def main():
start = default_timer()
n = str(factorial(100))
sum_ = 0
for i in range(len(n)):
sum_ = sum_ + int(n[i])
end = default_timer()
print('Project Euler, Problem 20')
print('Answer: {}'.format(sum_))
print('Elapsed time: {:.9f} seconds'.format(end - start))
if __name__ == '__main__':
main()