From 9da166b13c93dccc01f4ec6dd9740c2408ca8401 Mon Sep 17 00:00:00 2001 From: fa1l Date: Thu, 8 Oct 2020 12:07:16 +0500 Subject: [PATCH 1/8] improvements for project euler task 45 --- project_euler/problem_45/sol1.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/project_euler/problem_45/sol1.py b/project_euler/problem_45/sol1.py index ed66e6fab210..70750a3b6fc9 100644 --- a/project_euler/problem_45/sol1.py +++ b/project_euler/problem_45/sol1.py @@ -1,4 +1,6 @@ """ +https://projecteuler.net/problem=45 + Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Triangle T(n) = (n * (n + 1)) / 2 1, 3, 6, 10, 15, ... Pentagonal P(n) = (n * (3 * n − 1)) / 2 1, 5, 12, 22, 35, ... @@ -39,10 +41,10 @@ def is_pentagonal(n: int) -> bool: return ((1 + root) / 6) % 1 == 0 -def compute_num(start: int = 144) -> int: +def solution(start: int = 144) -> int: """ Returns the next number which is traingular, pentagonal and hexagonal. - >>> compute_num(144) + >>> solution(144) 1533776805 """ n = start @@ -54,4 +56,4 @@ def compute_num(start: int = 144) -> int: if __name__ == "__main__": - print(f"{compute_num(144)} = ") + print(f"{solution(144)} = ") From 7d4b39856272f0861e641387e3b7d1f527eb4e26 Mon Sep 17 00:00:00 2001 From: fa1l Date: Fri, 9 Oct 2020 08:32:46 +0500 Subject: [PATCH 2/8] fixed documentation --- project_euler/problem_45/sol1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_euler/problem_45/sol1.py b/project_euler/problem_45/sol1.py index 70750a3b6fc9..d48fffa3b636 100644 --- a/project_euler/problem_45/sol1.py +++ b/project_euler/problem_45/sol1.py @@ -1,5 +1,5 @@ """ -https://projecteuler.net/problem=45 +Problem 45: https://projecteuler.net/problem=45 Triangle, pentagonal, and hexagonal numbers are generated by the following formulae: Triangle T(n) = (n * (n + 1)) / 2 1, 3, 6, 10, 15, ... From e66c15dd6ee50151edc9c7a2ec75182a227a72c3 Mon Sep 17 00:00:00 2001 From: fa1l Date: Fri, 9 Oct 2020 10:23:54 +0500 Subject: [PATCH 3/8] update pe_16/sol1.py --- project_euler/problem_16/sol1.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/project_euler/problem_16/sol1.py b/project_euler/problem_16/sol1.py index 67c50ac87876..8c713197c905 100644 --- a/project_euler/problem_16/sol1.py +++ b/project_euler/problem_16/sol1.py @@ -1,11 +1,13 @@ """ +Problem 16: https://projecteuler.net/problem=16 + 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? """ -def solution(power): +def solution(power: int = 1000) -> int: """Returns the sum of the digits of the number 2^power. >>> solution(1000) 1366 @@ -28,7 +30,4 @@ def solution(power): if __name__ == "__main__": - power = int(input("Enter the power of 2: ").strip()) - print("2 ^ ", power, " = ", 2 ** power) - result = solution(power) - print("Sum of the digits is: ", result) + print(f"Sum of the digits is {solution(1000)}") From 763f5006d083565d9d796ef6a042dcfdb07dfcae Mon Sep 17 00:00:00 2001 From: fa1l Date: Fri, 9 Oct 2020 10:25:00 +0500 Subject: [PATCH 4/8] update pe_16/sol2.py --- project_euler/problem_16/sol2.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/project_euler/problem_16/sol2.py b/project_euler/problem_16/sol2.py index cd724d89a9e3..dd86388f6dcb 100644 --- a/project_euler/problem_16/sol2.py +++ b/project_euler/problem_16/sol2.py @@ -1,11 +1,13 @@ """ +Problem 16: https://projecteuler.net/problem=16 + 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26. What is the sum of the digits of the number 2^1000? """ -def solution(power): +def solution(power: int = 1000) -> int: """Returns the sum of the digits of the number 2^power. >>> solution(1000) @@ -25,4 +27,4 @@ def solution(power): if __name__ == "__main__": - print(solution(int(str(input()).strip()))) + print(f"Sum of the digits is {solution(1000)}") From a4d6769c95f5403bc3fd4e472651fb1743ea7b70 Mon Sep 17 00:00:00 2001 From: fa1l Date: Fri, 9 Oct 2020 10:41:01 +0500 Subject: [PATCH 5/8] revert solution changes for sol1 --- project_euler/problem_16/sol1.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/project_euler/problem_16/sol1.py b/project_euler/problem_16/sol1.py index 8c713197c905..113a5c0bf4fa 100644 --- a/project_euler/problem_16/sol1.py +++ b/project_euler/problem_16/sol1.py @@ -30,4 +30,7 @@ def solution(power: int = 1000) -> int: if __name__ == "__main__": - print(f"Sum of the digits is {solution(1000)}") + power = int(input("Enter the power of 2: ").strip()) + print("2 ^ ", power, " = ", 2 ** power) + result = solution(power) + print("Sum of the digits is: ", result) From 6a823e51ee1da6d58f1d5c5922df9d4920abe54c Mon Sep 17 00:00:00 2001 From: fa1l Date: Fri, 9 Oct 2020 10:41:42 +0500 Subject: [PATCH 6/8] revert solution changes for sol2 --- project_euler/problem_16/sol2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_euler/problem_16/sol2.py b/project_euler/problem_16/sol2.py index dd86388f6dcb..304d27d1e5d0 100644 --- a/project_euler/problem_16/sol2.py +++ b/project_euler/problem_16/sol2.py @@ -27,4 +27,4 @@ def solution(power: int = 1000) -> int: if __name__ == "__main__": - print(f"Sum of the digits is {solution(1000)}") + print(solution(int(str(input()).strip()))) From e9d9bbc07ba20ba850892bcc438b717442a2fc33 Mon Sep 17 00:00:00 2001 From: fa1l Date: Fri, 9 Oct 2020 11:23:57 +0500 Subject: [PATCH 7/8] remove trailing spaces in sol1 --- project_euler/problem_16/sol1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project_euler/problem_16/sol1.py b/project_euler/problem_16/sol1.py index 113a5c0bf4fa..f6620aa9482f 100644 --- a/project_euler/problem_16/sol1.py +++ b/project_euler/problem_16/sol1.py @@ -31,6 +31,6 @@ def solution(power: int = 1000) -> int: if __name__ == "__main__": power = int(input("Enter the power of 2: ").strip()) - print("2 ^ ", power, " = ", 2 ** power) - result = solution(power) + print("2 ^ ", power, " = ", 2 ** power) + result = solution(power) print("Sum of the digits is: ", result) From 5468c35dd3baf33f7e650067a093c00c1678d394 Mon Sep 17 00:00:00 2001 From: Dhruv Date: Fri, 9 Oct 2020 12:07:55 +0530 Subject: [PATCH 8/8] Update sol1.py --- project_euler/problem_45/sol1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project_euler/problem_45/sol1.py b/project_euler/problem_45/sol1.py index d48fffa3b636..cb30a4d97339 100644 --- a/project_euler/problem_45/sol1.py +++ b/project_euler/problem_45/sol1.py @@ -56,4 +56,4 @@ def solution(start: int = 144) -> int: if __name__ == "__main__": - print(f"{solution(144)} = ") + print(f"{solution()} = ")