From 220a742b6b2cb47a0a96e9d7a310e237dd3f6477 Mon Sep 17 00:00:00 2001 From: daviddoji Date: Sat, 1 Apr 2023 15:57:07 +0200 Subject: [PATCH] Unified numbers and output --- src/Python/Problems001-050/Problem001.py | 6 +++--- src/Python/Problems001-050/Problem002.py | 6 +++--- src/Python/Problems001-050/Problem003.py | 6 +++--- src/Python/Problems001-050/Problem004.py | 6 +++--- src/Python/Problems001-050/Problem005.py | 6 +++--- src/Python/Problems001-050/Problem006.py | 6 +++--- src/Python/Problems001-050/Problem007.py | 6 +++--- src/Python/Problems001-050/Problem008.py | 7 ++++--- src/Python/Problems001-050/Problem009.py | 6 +++--- src/Python/Problems001-050/Problem010.py | 6 +++--- src/Python/Problems001-050/Problem011.py | 6 +++--- src/Python/Problems001-050/Problem012.py | 6 +++--- src/Python/Problems001-050/Problem013.py | 11 ++++++----- src/Python/Problems001-050/Problem014.py | 6 +++--- src/Python/Problems001-050/Problem015.py | 10 ++++++---- src/Python/Problems001-050/Problem016.py | 10 ++++++---- src/Python/Problems001-050/Problem017.py | 13 +++++++------ src/Python/Problems001-050/Problem018.py | 6 +++--- src/Python/Problems001-050/Problem019.py | 13 +++++++------ src/Python/Problems001-050/Problem020.py | 6 +++--- src/Python/Problems001-050/Problem021.py | 6 +++--- src/Python/Problems001-050/Problem022.py | 8 ++++---- src/Python/Problems001-050/Problem023.py | 6 +++--- src/Python/Problems001-050/Problem024.py | 9 +++++---- src/Python/Problems001-050/Problem025.py | 6 +++--- src/Python/Problems001-050/Problem026.py | 6 +++--- src/Python/Problems001-050/Problem027.py | 6 +++--- src/Python/Problems001-050/Problem028.py | 6 +++--- src/Python/Problems001-050/Problem029.py | 6 +++--- src/Python/Problems001-050/Problem030.py | 6 +++--- src/Python/Problems001-050/Problem031.py | 7 ++++--- src/Python/Problems001-050/Problem032.py | 6 +++--- src/Python/Problems001-050/Problem033.py | 9 +++++---- src/Python/Problems001-050/Problem034.py | 7 +++---- src/Python/Problems001-050/Problem035.py | 7 +++---- src/Python/Problems001-050/Problem036.py | 6 +++--- src/Python/Problems001-050/Problem037.py | 7 +++---- src/Python/Problems001-050/Problem038.py | 7 +++---- src/Python/Problems001-050/Problem039.py | 6 +++--- src/Python/Problems001-050/Problem040.py | 6 +++--- src/Python/Problems001-050/Problem041.py | 22 +++++++++++----------- src/Python/Problems001-050/Problem042.py | 8 ++++---- src/Python/Problems001-050/Problem043.py | 7 ++++--- src/Python/Problems001-050/Problem044.py | 6 +++--- src/Python/Problems001-050/Problem045.py | 6 +++--- src/Python/Problems001-050/Problem046.py | 7 +++---- src/Python/Problems001-050/Problem047.py | 7 +++---- src/Python/Problems001-050/Problem048.py | 10 ++++++---- src/Python/Problems001-050/Problem049.py | 7 ++++--- src/Python/Problems001-050/Problem050.py | 6 +++--- 50 files changed, 188 insertions(+), 179 deletions(-) diff --git a/src/Python/Problems001-050/Problem001.py b/src/Python/Problems001-050/Problem001.py index 626a19b..5d53d9f 100644 --- a/src/Python/Problems001-050/Problem001.py +++ b/src/Python/Problems001-050/Problem001.py @@ -5,14 +5,14 @@ Created on 14 Mar 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 1 of Project Euler +Solution for problem 001 of Project Euler https://projecteuler.net/problem=1 """ from utils import timeit -@timeit("Problem 1") +@timeit("Problem 001") def compute(): """ If we list all the natural numbers below 10 that are multiples of 3 or 5, @@ -27,4 +27,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for problem 1 is {compute()}") + print(f"Result for problem 001: {compute()}") diff --git a/src/Python/Problems001-050/Problem002.py b/src/Python/Problems001-050/Problem002.py index 4154471..ebd3c23 100644 --- a/src/Python/Problems001-050/Problem002.py +++ b/src/Python/Problems001-050/Problem002.py @@ -5,14 +5,14 @@ Created on 14 Mar 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 2 of Project Euler +Solution for problem 002 of Project Euler https://projecteuler.net/problem=2 """ from utils import timeit -@timeit("Problem 2") +@timeit("Problem 002") def compute(): """ Each new term in the Fibonacci sequence is generated by adding the @@ -38,4 +38,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for problem 2 is {compute()}") + print(f"Result for problem 002: {compute()}") diff --git a/src/Python/Problems001-050/Problem003.py b/src/Python/Problems001-050/Problem003.py index e204521..71d53cc 100644 --- a/src/Python/Problems001-050/Problem003.py +++ b/src/Python/Problems001-050/Problem003.py @@ -5,14 +5,14 @@ Created on 18 Mar 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 3 of Project Euler +Solution for problem 003 of Project Euler https://projecteuler.net/problem=3 """ from utils import timeit -@timeit("Problem 3") +@timeit("Problem 003") def compute(): """ The prime factors of 13195 are 5, 7, 13 and 29. @@ -31,4 +31,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for problem 3 is {compute()}") + print(f"Result for problem 003: {compute()}") diff --git a/src/Python/Problems001-050/Problem004.py b/src/Python/Problems001-050/Problem004.py index 2a19c1c..ac291a2 100644 --- a/src/Python/Problems001-050/Problem004.py +++ b/src/Python/Problems001-050/Problem004.py @@ -5,14 +5,14 @@ Created on 18 Mar 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 4 of Project Euler +Solution for problem 004 of Project Euler https://projecteuler.net/problem=4 """ from utils import timeit -@timeit("Problem 4") +@timeit("Problem 004") def compute(): """ A palindromic number reads the same both ways. The largest palindrome made @@ -33,4 +33,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for problem 4 is {compute()}") + print(f"Result for problem 004: {compute()}") diff --git a/src/Python/Problems001-050/Problem005.py b/src/Python/Problems001-050/Problem005.py index 9df5c62..4eba8d6 100644 --- a/src/Python/Problems001-050/Problem005.py +++ b/src/Python/Problems001-050/Problem005.py @@ -5,7 +5,7 @@ Created on 23 Apr 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 5 of Project Euler +Solution for problem 005 of Project Euler https://projecteuler.net/problem=5 """ @@ -21,7 +21,7 @@ from utils import timeit # computing the LCM of two numbers, i.e. LCM(a, b, c) = LCM(a, LCM(b, c)) -@timeit("Problem 5") +@timeit("Problem 005") def compute(): """ 2520 is the smallest number that can be divided by each of the numbers @@ -39,4 +39,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for problem 5 is {compute()}") + print(f"Result for problem 005: {compute()}") diff --git a/src/Python/Problems001-050/Problem006.py b/src/Python/Problems001-050/Problem006.py index 8a4c614..8c31ac7 100644 --- a/src/Python/Problems001-050/Problem006.py +++ b/src/Python/Problems001-050/Problem006.py @@ -5,14 +5,14 @@ Created on 17 Jun 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 6 of Project Euler +Solution for problem 006 of Project Euler https://projecteuler.net/problem=6 """ from utils import timeit -@timeit("Problem 6") +@timeit("Problem 006") def compute(): """ The sum of the squares of the first ten natural numbers is, @@ -36,4 +36,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 6 is {compute()}") + print(f"Result for Problem 006: {compute()}") diff --git a/src/Python/Problems001-050/Problem007.py b/src/Python/Problems001-050/Problem007.py index 5f1b682..86174fe 100644 --- a/src/Python/Problems001-050/Problem007.py +++ b/src/Python/Problems001-050/Problem007.py @@ -5,14 +5,14 @@ Created on 28 Jun 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 7 of Project Euler +Solution for problem 007 of Project Euler https://projecteuler.net/problem=7 """ from utils import is_prime, timeit -@timeit("Problem 7") +@timeit("Problem 007") def compute(): """ By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see @@ -34,4 +34,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 7 is {compute()}") + print(f"Result for Problem 007: {compute()}") diff --git a/src/Python/Problems001-050/Problem008.py b/src/Python/Problems001-050/Problem008.py index 1a83470..7e1fc5c 100644 --- a/src/Python/Problems001-050/Problem008.py +++ b/src/Python/Problems001-050/Problem008.py @@ -5,7 +5,7 @@ Created on 28 Abr 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 8 of Project Euler +Solution for problem 008 of Project Euler https://projecteuler.net/problem=8 """ @@ -27,7 +27,7 @@ def sliding_window(iterable, n): yield tuple(window) -@timeit("Problem 8") +@timeit("Problem 008") def compute(): """ The four adjacent digits in the 1000-digit number that have the @@ -61,6 +61,7 @@ def compute(): 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450 """ + num = NUM.replace("\n", "").replace(" ", "") adjacent_digits = 13 ans = 0 @@ -75,4 +76,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 8 is {compute()}") + print(f"Result for Problem 008: {compute()}") diff --git a/src/Python/Problems001-050/Problem009.py b/src/Python/Problems001-050/Problem009.py index ef08e18..98a09fb 100644 --- a/src/Python/Problems001-050/Problem009.py +++ b/src/Python/Problems001-050/Problem009.py @@ -5,14 +5,14 @@ Created on 26 Aug 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 9 of Project Euler +Solution for problem 009 of Project Euler https://projecteuler.net/problem=9 """ from utils import timeit -@timeit("Problem 9") +@timeit("Problem 009") def compute(): """ A Pythagorean triplet is a set of three natural numbers, a < b < c, @@ -34,4 +34,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 9 is {compute()}") + print(f"Result for Problem 009: {compute()}") diff --git a/src/Python/Problems001-050/Problem010.py b/src/Python/Problems001-050/Problem010.py index ca8f7dc..4b0103d 100644 --- a/src/Python/Problems001-050/Problem010.py +++ b/src/Python/Problems001-050/Problem010.py @@ -5,14 +5,14 @@ Created on 26 Aug 2017 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 10 of Project Euler +Solution for problem 010 of Project Euler https://projecteuler.net/problem=10 """ from utils import list_primes, timeit -@timeit("Problem 10") +@timeit("Problem 010") def compute(): """ The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. @@ -26,4 +26,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 10 is {compute()}") + print(f"Result for Problem 010: {compute()}") diff --git a/src/Python/Problems001-050/Problem011.py b/src/Python/Problems001-050/Problem011.py index 6e28521..bc69578 100644 --- a/src/Python/Problems001-050/Problem011.py +++ b/src/Python/Problems001-050/Problem011.py @@ -5,7 +5,7 @@ Created on 07 Jul 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 11 of Project Euler +Solution for problem 011 of Project Euler https://projecteuler.net/problem=11 """ @@ -42,7 +42,7 @@ def grid_product(x, y, dx, dy, n): return result -@timeit("Problem 11") +@timeit("Problem 011") def compute(): """ In the 20x20 grid above, four numbers along a diagonal line have been @@ -72,4 +72,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 11 is {compute()}") + print(f"Result for Problem 011: {compute()}") diff --git a/src/Python/Problems001-050/Problem012.py b/src/Python/Problems001-050/Problem012.py index 00610ed..9826ba9 100644 --- a/src/Python/Problems001-050/Problem012.py +++ b/src/Python/Problems001-050/Problem012.py @@ -5,7 +5,7 @@ Created on 01 Jan 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 12 of Project Euler +Solution for problem 012 of Project Euler https://projecteuler.net/problem=12 """ @@ -27,7 +27,7 @@ def num_divisors(n): return 2 * len(divs) -@timeit("Problem 12") +@timeit("Problem 012") def compute(): """ The sequence of triangle numbers is generated by adding the natural @@ -63,4 +63,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 12 is {compute()}") + print(f"Result for Problem 012: {compute()}") diff --git a/src/Python/Problems001-050/Problem013.py b/src/Python/Problems001-050/Problem013.py index 011e420..b2acbfd 100644 --- a/src/Python/Problems001-050/Problem013.py +++ b/src/Python/Problems001-050/Problem013.py @@ -5,7 +5,7 @@ Created on 1 Jan 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 13 of Project Euler +Solution for problem 013 of Project Euler https://projecteuler.net/problem=13 """ @@ -14,14 +14,15 @@ from pathlib import Path from utils import timeit -@timeit("Problem 13") +@timeit("Problem 013") def compute(): """ Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. """ - _file = Path("../files/Problem13.txt") - with open(_file, "r") as f: + + file = Path("files/Problem13.txt") + with open(file, "r") as f: num = f.readlines() ans = 0 for line in num: @@ -31,4 +32,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 13 is {compute()}") + print(f"Result for Problem 013: {compute()}") diff --git a/src/Python/Problems001-050/Problem014.py b/src/Python/Problems001-050/Problem014.py index c315b3a..fee5a69 100644 --- a/src/Python/Problems001-050/Problem014.py +++ b/src/Python/Problems001-050/Problem014.py @@ -5,7 +5,7 @@ Created on 7 Jan 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 14 of Project Euler +Solution for problem 014 of Project Euler https://projecteuler.net/problem=14 """ @@ -26,7 +26,7 @@ def chain_length(n, terms): return length -@timeit("Problem 14") +@timeit("Problem 014") def compute(): """ The following iterative sequence is defined for the set of positive @@ -63,4 +63,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 14 is {compute()}") + print(f"Result for Problem 014: {compute()}") diff --git a/src/Python/Problems001-050/Problem015.py b/src/Python/Problems001-050/Problem015.py index 4e9cdf5..858e1d4 100644 --- a/src/Python/Problems001-050/Problem015.py +++ b/src/Python/Problems001-050/Problem015.py @@ -5,7 +5,7 @@ Created on 7 Jan 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 15 of Project Euler +Solution for problem 015 of Project Euler https://projecteuler.net/problem=15 """ @@ -14,7 +14,7 @@ from math import factorial from utils import timeit -@timeit("Problem 15") +@timeit("Problem 015") def compute(): """ Starting in the top left corner of a 2x2 grid, and only being able to @@ -25,8 +25,10 @@ def compute(): """ n = 20 - return int(factorial(2 * n) / (factorial(n) * factorial(2 * n - n))) + ans = int(factorial(2 * n) / (factorial(n) * factorial(2 * n - n))) + + return ans if __name__ == "__main__": - print(f"Result for Problem 15 is {compute()}") + print(f"Result for Problem 015: {compute()}") diff --git a/src/Python/Problems001-050/Problem016.py b/src/Python/Problems001-050/Problem016.py index 034a405..e2f00d9 100644 --- a/src/Python/Problems001-050/Problem016.py +++ b/src/Python/Problems001-050/Problem016.py @@ -5,14 +5,14 @@ Created on 13 Jan 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 16 of Project Euler +Solution for problem 016 of Project Euler https://projecteuler.net/problem=16 """ from utils import timeit -@timeit("Problem 16") +@timeit("Problem 016") def compute(): """ 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. @@ -21,8 +21,10 @@ def compute(): """ n = 1000 - return sum(int(digit) for digit in str(2**n)) + ans = sum(int(digit) for digit in str(2**n)) + + return ans if __name__ == "__main__": - print(f"Result for Problem 16 is {compute()}") + print(f"Result for Problem 016: {compute()}") diff --git a/src/Python/Problems001-050/Problem017.py b/src/Python/Problems001-050/Problem017.py index c6e9b4d..c1d37ee 100644 --- a/src/Python/Problems001-050/Problem017.py +++ b/src/Python/Problems001-050/Problem017.py @@ -5,7 +5,7 @@ Created on 13 Jan 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 17 of Project Euler +Solution for problem 017 of Project Euler https://projecteuler.net/problem=17 """ @@ -67,7 +67,7 @@ def num_to_letters(num): return num_to_letters(thousands) + len(nums[1000]) -@timeit("Problem 17") +@timeit("Problem 017") def compute(): """ If the numbers 1 to 5 are written out in words: one, two, three, four, @@ -83,11 +83,12 @@ def compute(): """ n = 1000 - letters = 0 + ans = 0 for num in range(1, n + 1): - letters += num_to_letters(num) - return letters + ans += num_to_letters(num) + + return ans if __name__ == "__main__": - print(f"Result for Problem 17 is {compute()}") + print(f"Result for Problem 017: {compute()}") diff --git a/src/Python/Problems001-050/Problem018.py b/src/Python/Problems001-050/Problem018.py index fa29c11..3291229 100644 --- a/src/Python/Problems001-050/Problem018.py +++ b/src/Python/Problems001-050/Problem018.py @@ -5,7 +5,7 @@ Created on 15 Sep 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 18 of Project Euler +Solution for problem 018 of Project Euler https://projecteuler.net/problem=18 """ @@ -30,7 +30,7 @@ triangle = [ ] -@timeit("Problem 18") +@timeit("Problem 018") def compute(): """ By starting at the top of the triangle below and moving to adjacent @@ -54,4 +54,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 18 is {compute()}") + print(f"Result for Problem 018: {compute()}") diff --git a/src/Python/Problems001-050/Problem019.py b/src/Python/Problems001-050/Problem019.py index b3c6fde..29ab31e 100644 --- a/src/Python/Problems001-050/Problem019.py +++ b/src/Python/Problems001-050/Problem019.py @@ -5,7 +5,7 @@ Created on 15 Sep 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 19 of Project Euler +Solution for problem 019 of Project Euler https://projecteuler.net/problem=19 """ @@ -14,7 +14,7 @@ from datetime import date from utils import timeit -@timeit("Problem 19") +@timeit("Problem 019") def compute(): """ You are given the following information, but you may prefer to do some @@ -33,13 +33,14 @@ def compute(): century (1 Jan 1901 to 31 Dec 2000)? """ - sundays = 0 + ans = 0 for year in range(1901, 2001): for month in range(1, 13): if date(year, month, 1).weekday() == 6: - sundays += 1 - return sundays + ans += 1 + + return ans if __name__ == "__main__": - print(f"Result for Problem 19 is {compute()}") + print(f"Result for Problem 019: {compute()}") diff --git a/src/Python/Problems001-050/Problem020.py b/src/Python/Problems001-050/Problem020.py index 231f00d..11af585 100644 --- a/src/Python/Problems001-050/Problem020.py +++ b/src/Python/Problems001-050/Problem020.py @@ -5,7 +5,7 @@ Created on 15 Sep 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 20 of Project Euler +Solution for problem 020 of Project Euler https://projecteuler.net/problem=20 """ @@ -14,7 +14,7 @@ from math import factorial from utils import timeit -@timeit("Problem 20") +@timeit("Problem 020") def compute(): """ n! means n x (n - 1) x ... x 3 x 2 x 1 @@ -33,4 +33,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 20 is {compute()}") + print(f"Result for Problem 020: {compute()}") diff --git a/src/Python/Problems001-050/Problem021.py b/src/Python/Problems001-050/Problem021.py index 9966130..81f2e51 100644 --- a/src/Python/Problems001-050/Problem021.py +++ b/src/Python/Problems001-050/Problem021.py @@ -5,7 +5,7 @@ Created on 15 Sep 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 21 of Project Euler +Solution for problem 021 of Project Euler https://projecteuler.net/problem=21 """ @@ -16,7 +16,7 @@ def sum_divisors(n): return sum(i for i in range(1, n // 2 + 1) if n % i == 0) -@timeit("Problem 21") +@timeit("Problem 021") def compute(): """ Let d(n) be defined as the sum of proper divisors of n (numbers @@ -42,4 +42,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 21 is {compute()}") + print(f"Result for Problem 021: {compute()}") diff --git a/src/Python/Problems001-050/Problem022.py b/src/Python/Problems001-050/Problem022.py index 4fbc765..a38fb7e 100644 --- a/src/Python/Problems001-050/Problem022.py +++ b/src/Python/Problems001-050/Problem022.py @@ -5,7 +5,7 @@ Created on 31 Dec 2018 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 22 of Project Euler +Solution for problem 022 of Project Euler https://projecteuler.net/problem=22 """ @@ -14,7 +14,7 @@ from pathlib import Path from utils import timeit -@timeit("Problem 22") +@timeit("Problem 022") def compute(): """ Using names.txt, a 46K text file containing over five-thousand first names, @@ -29,7 +29,7 @@ def compute(): What is the total of all the name scores in the file? """ - file = Path("../files/Problem22.txt") + file = Path("files/Problem22.txt") with open(file, "r") as f: names = sorted(f.read().replace('"', "").split(",")) @@ -41,4 +41,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 22 is {compute()}") + print(f"Result for Problem 022: {compute()}") diff --git a/src/Python/Problems001-050/Problem023.py b/src/Python/Problems001-050/Problem023.py index 19a052b..9c3283a 100644 --- a/src/Python/Problems001-050/Problem023.py +++ b/src/Python/Problems001-050/Problem023.py @@ -5,7 +5,7 @@ Created on 05 Jan 2019 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 23 of Project Euler +Solution for problem 023 of Project Euler https://projecteuler.net/problem=23 """ @@ -13,7 +13,7 @@ https://projecteuler.net/problem=23 from utils import timeit -@timeit("Problem 23") +@timeit("Problem 023") def compute(): """ A perfect number is a number for which the sum of its proper divisors is @@ -58,4 +58,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 23 is {compute()}") + print(f"Result for Problem 023: {compute()}") diff --git a/src/Python/Problems001-050/Problem024.py b/src/Python/Problems001-050/Problem024.py index a41bb49..5dc2604 100644 --- a/src/Python/Problems001-050/Problem024.py +++ b/src/Python/Problems001-050/Problem024.py @@ -5,7 +5,7 @@ Created on 11 Sep 2019 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 24 of Project Euler +Solution for problem 024 of Project Euler https://projecteuler.net/problem=24 """ @@ -14,7 +14,7 @@ from itertools import permutations from utils import timeit -@timeit("Problem 24") +@timeit("Problem 024") def compute(): """ A permutation is an ordered arrangement of objects. For example, 3124 is @@ -30,9 +30,10 @@ def compute(): digits = list(range(10)) _permutations = list(permutations(digits)) + ans = "".join(str(digit) for digit in _permutations[999_999]) - return "".join(str(digit) for digit in _permutations[999_999]) + return ans if __name__ == "__main__": - print(f"Result for Problem 24 is {compute()}") + print(f"Result for Problem 024: {compute()}") diff --git a/src/Python/Problems001-050/Problem025.py b/src/Python/Problems001-050/Problem025.py index 7fcbacd..c8ad510 100644 --- a/src/Python/Problems001-050/Problem025.py +++ b/src/Python/Problems001-050/Problem025.py @@ -5,14 +5,14 @@ Created on 11 Sep 2019 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 25 of Project Euler +Solution for problem 025 of Project Euler https://projecteuler.net/problem=25 """ from utils import timeit -@timeit("Problem 25") +@timeit("Problem 025") def compute(): """ The Fibonacci sequence is defined by the recurrence relation: @@ -50,4 +50,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 25 is {compute()}") + print(f"Result for Problem 025: {compute()}") diff --git a/src/Python/Problems001-050/Problem026.py b/src/Python/Problems001-050/Problem026.py index abfc519..0e4c08c 100644 --- a/src/Python/Problems001-050/Problem026.py +++ b/src/Python/Problems001-050/Problem026.py @@ -5,14 +5,14 @@ Created on 11 Sep 2019 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 26 of Project Euler +Solution for problem 026 of Project Euler https://projecteuler.net/problem=26 """ from utils import timeit -@timeit("Problem 26") +@timeit("Problem 026") def compute(): """ A unit fraction contains 1 in the numerator. The decimal representation @@ -50,4 +50,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 26 is {compute()}") + print(f"Result for Problem 026: {compute()}") diff --git a/src/Python/Problems001-050/Problem027.py b/src/Python/Problems001-050/Problem027.py index 03caeb3..1f2a7f2 100644 --- a/src/Python/Problems001-050/Problem027.py +++ b/src/Python/Problems001-050/Problem027.py @@ -5,14 +5,14 @@ Created on 15 Sep 2019 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 27 of Project Euler +Solution for problem 027 of Project Euler https://projecteuler.net/problem=27 """ from utils import is_prime, timeit -@timeit("Problem 27") +@timeit("Problem 027") def compute(): """ Euler discovered the remarkable quadratic formula: @@ -56,4 +56,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 27 is {compute()}") + print(f"Result for Problem 027: {compute()}") diff --git a/src/Python/Problems001-050/Problem028.py b/src/Python/Problems001-050/Problem028.py index d5ee8e2..21d5ff8 100644 --- a/src/Python/Problems001-050/Problem028.py +++ b/src/Python/Problems001-050/Problem028.py @@ -5,14 +5,14 @@ Created on 3 Jan 2020 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 28 of Project Euler +Solution for problem 028 of Project Euler https://projecteuler.net/problem=28 """ from utils import timeit -@timeit("Problem 28") +@timeit("Problem 028") def compute(): """ Starting with the number 1 and moving to the right in a clockwise @@ -45,4 +45,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 28 is {compute()}") + print(f"Result for Problem 028: {compute()}") diff --git a/src/Python/Problems001-050/Problem029.py b/src/Python/Problems001-050/Problem029.py index 7319b7f..754b5cb 100644 --- a/src/Python/Problems001-050/Problem029.py +++ b/src/Python/Problems001-050/Problem029.py @@ -5,7 +5,7 @@ Created on 3 Jan 2020 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 29 of Project Euler +Solution for problem 029 of Project Euler https://projecteuler.net/problem=29 """ from itertools import product @@ -13,7 +13,7 @@ from itertools import product from utils import timeit -@timeit("Problem 29") +@timeit("Problem 029") def compute(): """ Consider all integer combinations of ab for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5: @@ -38,4 +38,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 29 is {compute()}") + print(f"Result for Problem 029: {compute()}") diff --git a/src/Python/Problems001-050/Problem030.py b/src/Python/Problems001-050/Problem030.py index fdb0344..cb50ac7 100644 --- a/src/Python/Problems001-050/Problem030.py +++ b/src/Python/Problems001-050/Problem030.py @@ -5,7 +5,7 @@ Created on 3 Jan 2020 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 30 of Project Euler +Solution for problem 030 of Project Euler https://projecteuler.net/problem=30 """ @@ -16,7 +16,7 @@ def power_digit_sum(pow, n): return sum(int(c) ** pow for c in str(n)) -@timeit("Problem 30") +@timeit("Problem 030") def compute(): """ Surprisingly there are only three numbers that can be written as the sum @@ -40,4 +40,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 30 is {compute()}") + print(f"Result for Problem 030: {compute()}") diff --git a/src/Python/Problems001-050/Problem031.py b/src/Python/Problems001-050/Problem031.py index 1e458f6..c648a7b 100644 --- a/src/Python/Problems001-050/Problem031.py +++ b/src/Python/Problems001-050/Problem031.py @@ -5,7 +5,7 @@ Created on 24 Feb 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 31 of Project Euler +Solution for problem 031 of Project Euler https://projecteuler.net/problem=31 """ @@ -14,7 +14,7 @@ from itertools import product from utils import timeit -@timeit("Problem 31") +@timeit("Problem 031") def compute(): """ In the United Kingdom the currency is made up of pound (£) and pence (p). @@ -29,6 +29,7 @@ def compute(): How many different ways can £2 be made using any number of coins? """ + ans = 0 coins = [2, 5, 10, 20, 50, 100] bunch_of_coins = product(*[range(0, 201, i) for i in coins]) @@ -42,4 +43,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 31 is {compute()}") + print(f"Result for Problem 031: {compute()}") diff --git a/src/Python/Problems001-050/Problem032.py b/src/Python/Problems001-050/Problem032.py index 1e7545c..7773775 100644 --- a/src/Python/Problems001-050/Problem032.py +++ b/src/Python/Problems001-050/Problem032.py @@ -5,14 +5,14 @@ Created on 26 Feb 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 32 of Project Euler +Solution for problem 032 of Project Euler https://projecteuler.net/problem=32 """ from utils import timeit -@timeit("Problem 32") +@timeit("Problem 032") def compute(): """ We shall say that an n-digit number is pandigital if it makes use of all @@ -41,4 +41,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 32 is {compute()}") + print(f"Result for Problem 032: {compute()}") diff --git a/src/Python/Problems001-050/Problem033.py b/src/Python/Problems001-050/Problem033.py index 9efb4a5..dbe6d97 100644 --- a/src/Python/Problems001-050/Problem033.py +++ b/src/Python/Problems001-050/Problem033.py @@ -5,14 +5,14 @@ Created on 04 Mar 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 33 of Project Euler +Solution for problem 033 of Project Euler https://projecteuler.net/problem=33 """ from utils import timeit -@timeit("Problem 33") +@timeit("Problem 033") def compute(): """ The fraction 49/98 is a curious fraction, as an inexperienced mathematician @@ -39,9 +39,10 @@ def compute(): if int(str(x)[0]) / int(str(y)[1]) == x / y: numerator *= x denominator *= y + ans = int(denominator / numerator) - return int(denominator / numerator) + return ans if __name__ == "__main__": - print(f"Result for Problem 33 is {compute()}") + print(f"Result for Problem 033: {compute()}") diff --git a/src/Python/Problems001-050/Problem034.py b/src/Python/Problems001-050/Problem034.py index ac05b90..07fd77a 100644 --- a/src/Python/Problems001-050/Problem034.py +++ b/src/Python/Problems001-050/Problem034.py @@ -5,7 +5,7 @@ Created on 02 Apr 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 34 of Project Euler +Solution for problem 034 of Project Euler https://projecteuler.net/problem=34 """ @@ -14,7 +14,7 @@ from math import factorial from utils import timeit -@timeit("Problem 34") +@timeit("Problem 034") def compute(): """ 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. @@ -26,7 +26,6 @@ def compute(): """ ans = 0 - for num in range(10, 2_540_160): sum_of_factorial = 0 for digit in str(num): @@ -38,4 +37,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 34 is {compute()}") + print(f"Result for Problem 034: {compute()}") diff --git a/src/Python/Problems001-050/Problem035.py b/src/Python/Problems001-050/Problem035.py index a7c210d..c43e9e6 100644 --- a/src/Python/Problems001-050/Problem035.py +++ b/src/Python/Problems001-050/Problem035.py @@ -5,7 +5,7 @@ Created on 02 Apr 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 35 of Project Euler +Solution for problem 035 of Project Euler https://projecteuler.net/problem=35 """ @@ -17,11 +17,10 @@ def circular_number(number): ans = [] for i in range(len(num_str)): ans.append(int(num_str[i:] + num_str[:i])) - return ans -@timeit("Problem 35") +@timeit("Problem 035") def compute(): """ The number, 197, is called a circular prime because all rotations of the @@ -48,4 +47,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 35 is {compute()}") + print(f"Result for Problem 035: {compute()}") diff --git a/src/Python/Problems001-050/Problem036.py b/src/Python/Problems001-050/Problem036.py index de8b6d0..c9ea998 100644 --- a/src/Python/Problems001-050/Problem036.py +++ b/src/Python/Problems001-050/Problem036.py @@ -5,7 +5,7 @@ Created on 08 Apr 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 36 of Project Euler +Solution for problem 036 of Project Euler https://projecteuler.net/problem=36 """ @@ -16,7 +16,7 @@ def is_palidrome(num): return str(num) == str(num)[::-1] -@timeit("Problem 36") +@timeit("Problem 036") def compute(): """ The decimal number, 585 = 1001001001_2 (binary), is palindromic @@ -35,4 +35,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 36 is {compute()}") + print(f"Result for Problem 036: {compute()}") diff --git a/src/Python/Problems001-050/Problem037.py b/src/Python/Problems001-050/Problem037.py index c8a49c1..31bcf32 100644 --- a/src/Python/Problems001-050/Problem037.py +++ b/src/Python/Problems001-050/Problem037.py @@ -5,7 +5,7 @@ Created on 09 Apr 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 37 of Project Euler +Solution for problem 037 of Project Euler https://projecteuler.net/problem=37 """ @@ -17,11 +17,10 @@ def is_truncatable_prime(number): for i in range(1, len(num_str)): if not is_prime(int(num_str[i:])) or not is_prime(int(num_str[:-i])): return False - return True -@timeit("Problem 37") +@timeit("Problem 037") def compute(): """ The number 3797 has an interesting property. Being prime itself, it is @@ -46,4 +45,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 37 is {compute()}") + print(f"Result for Problem 037: {compute()}") diff --git a/src/Python/Problems001-050/Problem038.py b/src/Python/Problems001-050/Problem038.py index 125bb5b..9cb3a5d 100644 --- a/src/Python/Problems001-050/Problem038.py +++ b/src/Python/Problems001-050/Problem038.py @@ -5,14 +5,14 @@ Created on 03 Jun 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 38 of Project Euler +Solution for problem 038 of Project Euler https://projecteuler.net/problem=38 """ from utils import timeit -@timeit("Problem 38") +@timeit("Problem 038") def compute(): """ Take the number 192 and multiply it by each of 1, 2, and 3: @@ -44,11 +44,10 @@ def compute(): number += str(integer * i) if sorted(number) == list("123456789"): ans.append(number) - integer += 1 return max(ans) if __name__ == "__main__": - print(f"Result for Problem 38 is {compute()}") + print(f"Result for Problem 038: {compute()}") diff --git a/src/Python/Problems001-050/Problem039.py b/src/Python/Problems001-050/Problem039.py index 4b22390..478cb18 100644 --- a/src/Python/Problems001-050/Problem039.py +++ b/src/Python/Problems001-050/Problem039.py @@ -5,14 +5,14 @@ Created on 05 Jun 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 39 of Project Euler +Solution for problem 039 of Project Euler https://projecteuler.net/problem=39 """ from utils import timeit -@timeit("Problem 39") +@timeit("Problem 039") def compute(): """ If p is the perimeter of a right angle triangle with integral length sides, @@ -42,4 +42,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 39 is {compute()}") + print(f"Result for Problem 039: {compute()}") diff --git a/src/Python/Problems001-050/Problem040.py b/src/Python/Problems001-050/Problem040.py index 47294a2..c0f3ce9 100644 --- a/src/Python/Problems001-050/Problem040.py +++ b/src/Python/Problems001-050/Problem040.py @@ -5,14 +5,14 @@ Created on 23 Jun 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 40 of Project Euler +Solution for problem 040 of Project Euler https://projecteuler.net/problem=40 """ from utils import timeit -@timeit("Problem 40") +@timeit("Problem 040") def compute(): """ An irrational decimal fraction is created by concatenating the positive @@ -41,4 +41,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 40 is {compute()}") + print(f"Result for Problem 040: {compute()}") diff --git a/src/Python/Problems001-050/Problem041.py b/src/Python/Problems001-050/Problem041.py index 04ea861..924047e 100644 --- a/src/Python/Problems001-050/Problem041.py +++ b/src/Python/Problems001-050/Problem041.py @@ -5,14 +5,22 @@ Created on 29 Jun 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 41 of Project Euler +Solution for problem 041 of Project Euler https://projecteuler.net/problem=41 """ from utils import is_prime, timeit -@timeit("Problem 41") +def is_pandigital(number): + number = sorted(str(number)) + check = [str(i) for i in range(1, len(number) + 1)] + if number == check: + return True + return False + + +@timeit("Problem 041") def compute(): """ We shall say that an n-digit number is pandigital if it makes @@ -22,14 +30,6 @@ def compute(): What is the largest n-digit pandigital prime that exists? """ - def is_pandigital(number): - number = sorted(str(number)) - check = [str(i) for i in range(1, len(number) + 1)] - if number == check: - return True - - return False - for ans in range(7654321, 1, -1): if is_pandigital(ans): if is_prime(ans): @@ -37,4 +37,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 41 is {compute()}") + print(f"Result for Problem 041: {compute()}") diff --git a/src/Python/Problems001-050/Problem042.py b/src/Python/Problems001-050/Problem042.py index b57c7b3..0b303e4 100644 --- a/src/Python/Problems001-050/Problem042.py +++ b/src/Python/Problems001-050/Problem042.py @@ -5,7 +5,7 @@ Created on 26 Jul 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 42 of Project Euler +Solution for problem 042 of Project Euler https://projecteuler.net/problem=42 """ @@ -22,7 +22,7 @@ def word_to_value(word): return sum(ord(letter) - 64 for letter in word) -@timeit("Problem 42") +@timeit("Problem 042") def compute(): """ The nth term of the sequence of triangle numbers is given by, @@ -42,7 +42,7 @@ def compute(): triangular_numbers = [triangle_number(n) for n in range(27)] ans = 0 - file = Path("../files/Problem42.txt") + file = Path("files/Problem42.txt") with open(file, "r") as f: words = f.readline().strip('"').split('","') for word in words: @@ -53,4 +53,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 42 is {compute()}") + print(f"Result for Problem 042: {compute()}") diff --git a/src/Python/Problems001-050/Problem043.py b/src/Python/Problems001-050/Problem043.py index 40f7f60..93041e2 100644 --- a/src/Python/Problems001-050/Problem043.py +++ b/src/Python/Problems001-050/Problem043.py @@ -5,7 +5,7 @@ Created on 03 Aug 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 43 of Project Euler +Solution for problem 043 of Project Euler https://projecteuler.net/problem=43 """ @@ -14,7 +14,7 @@ from itertools import permutations from utils import timeit -@timeit("Problem 43") +@timeit("Problem 043") def compute(): """ The number, 1406357289, is a 0 to 9 pandigital number because @@ -34,6 +34,7 @@ def compute(): Find the sum of all 0 to 9 pandigital numbers with this property. """ + ans = [] pandigital = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] @@ -53,4 +54,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 43 is {compute()}") + print(f"Result for Problem 043: {compute()}") diff --git a/src/Python/Problems001-050/Problem044.py b/src/Python/Problems001-050/Problem044.py index 60a6689..02208b5 100644 --- a/src/Python/Problems001-050/Problem044.py +++ b/src/Python/Problems001-050/Problem044.py @@ -5,7 +5,7 @@ Created on 30 Aug 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 44 of Project Euler +Solution for problem 044 of Project Euler https://projecteuler.net/problem=44 """ @@ -19,7 +19,7 @@ def pentagonal(n): return int(n * (3 * n - 1) / 2) -@timeit("Problem 44") +@timeit("Problem 044") def compute(): """ Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2. @@ -49,4 +49,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 44 is {compute()}") + print(f"Result for Problem 044: {compute()}") diff --git a/src/Python/Problems001-050/Problem045.py b/src/Python/Problems001-050/Problem045.py index 4c396e0..7548009 100644 --- a/src/Python/Problems001-050/Problem045.py +++ b/src/Python/Problems001-050/Problem045.py @@ -5,7 +5,7 @@ Created on 09 Sep 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 45 of Project Euler +Solution for problem 045 of Project Euler https://projecteuler.net/problem=45 """ @@ -20,7 +20,7 @@ def hexagonal(n): return int(n * (2 * n - 1)) -@timeit("Problem 45") +@timeit("Problem 045") def compute(): """ Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: @@ -43,4 +43,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 45 is {compute()}") + print(f"Result for Problem 045: {compute()}") diff --git a/src/Python/Problems001-050/Problem046.py b/src/Python/Problems001-050/Problem046.py index 5a912d0..df8dd1f 100644 --- a/src/Python/Problems001-050/Problem046.py +++ b/src/Python/Problems001-050/Problem046.py @@ -5,7 +5,7 @@ Created on 12 Sep 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 46 of Project Euler +Solution for problem 046 of Project Euler https://projecteuler.net/problem=46 """ @@ -16,11 +16,10 @@ def is_goldbach(number): for i in range(number - 1, 1, -1): if is_prime(i) and ((number - i) / 2) ** 0.5 % 1 == 0: return True - return False -@timeit("Problem 46") +@timeit("Problem 046") def compute(): """ It was proposed by Christian Goldbach that every odd composite number @@ -47,4 +46,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 46 is {compute()}") + print(f"Result for Problem 046: {compute()}") diff --git a/src/Python/Problems001-050/Problem047.py b/src/Python/Problems001-050/Problem047.py index fb4faee..dda4b6e 100644 --- a/src/Python/Problems001-050/Problem047.py +++ b/src/Python/Problems001-050/Problem047.py @@ -5,7 +5,7 @@ Created on 12 Sep 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 47 of Project Euler +Solution for problem 047 of Project Euler https://projecteuler.net/problem=47 """ @@ -23,11 +23,10 @@ def factor(n): d += 1 if n > 1: ans.append(n) - return ans -@timeit("Problem 47") +@timeit("Problem 047") def compute(): """ The first two consecutive numbers to have two distinct prime factors are: @@ -61,4 +60,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 47 is {compute()}") + print(f"Result for Problem 047: {compute()}") diff --git a/src/Python/Problems001-050/Problem048.py b/src/Python/Problems001-050/Problem048.py index 56eb942..9aadeee 100644 --- a/src/Python/Problems001-050/Problem048.py +++ b/src/Python/Problems001-050/Problem048.py @@ -5,14 +5,14 @@ Created on 12 Sep 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 48 of Project Euler +Solution for problem 048 of Project Euler https://projecteuler.net/problem=48 """ from utils import timeit -@timeit("Problem 48") +@timeit("Problem 048") def compute(): """ The series, 1^1 + 2^2 + 3^3 + ... + 10^10 = 10405071317. @@ -21,8 +21,10 @@ def compute(): """ series = sum(i**i for i in range(1, 1001)) - return str(series)[-10:] + ans = str(series)[-10:] + + return ans if __name__ == "__main__": - print(f"Result for Problem 48 is {compute()}") + print(f"Result for Problem 048: {compute()}") diff --git a/src/Python/Problems001-050/Problem049.py b/src/Python/Problems001-050/Problem049.py index 6d5e37f..a61009f 100644 --- a/src/Python/Problems001-050/Problem049.py +++ b/src/Python/Problems001-050/Problem049.py @@ -5,14 +5,14 @@ Created on 18 Sep 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 49 of Project Euler +Solution for problem 049 of Project Euler https://projecteuler.net/problem=49 """ from utils import list_primes, timeit -@timeit("Problem 49") +@timeit("Problem 049") def compute(): """ The arithmetic sequence, 1487, 4817, 8147, in which each of the terms @@ -39,9 +39,10 @@ def compute(): ): if number + 3330 in primes_list and number + 6660 in primes_list: ans.append(str(number) + str(number + 3300) + str(number + 6660)) + # return the second one return ans[1] if __name__ == "__main__": - print(f"Result for Problem 49 is {compute()}") + print(f"Result for Problem 049: {compute()}") diff --git a/src/Python/Problems001-050/Problem050.py b/src/Python/Problems001-050/Problem050.py index 687d7d8..2475b4f 100644 --- a/src/Python/Problems001-050/Problem050.py +++ b/src/Python/Problems001-050/Problem050.py @@ -5,14 +5,14 @@ Created on 18 Sep 2021 @author: David Doblas Jiménez @email: daviddoji@pm.me -Solution for problem 50 of Project Euler +Solution for problem 050 of Project Euler https://projecteuler.net/problem=50 """ from utils import is_prime, list_primes, timeit -@timeit("Problem 50") +@timeit("Problem 050") def compute(): """ The prime 41, can be written as the sum of six consecutive primes: @@ -49,4 +49,4 @@ def compute(): if __name__ == "__main__": - print(f"Result for Problem 50 is {compute()}") + print(f"Result for Problem 050: {compute()}")