From 606cf399b9c587775277ede303622b310b8bd8fc Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Thu, 19 Sep 2019 21:43:55 +0200 Subject: [PATCH] Add more python solutions Added python solutions for problems 19 and 20 --- Python/p019.py | 25 +++++++++++++++++++++++++ Python/p020.py | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Python/p019.py create mode 100644 Python/p020.py diff --git a/Python/p019.py b/Python/p019.py new file mode 100644 index 0000000..1cb1577 --- /dev/null +++ b/Python/p019.py @@ -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() diff --git a/Python/p020.py b/Python/p020.py new file mode 100644 index 0000000..5ec0692 --- /dev/null +++ b/Python/p020.py @@ -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()