Add more python solutions
Added python solutions for problems 19 and 20
This commit is contained in:
parent
eedc0d1271
commit
606cf399b9
25
Python/p019.py
Normal file
25
Python/p019.py
Normal 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
25
Python/p020.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user