From 9d90a5e6e83e83f58ddaad2c3ba6eab39f0c0863 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Torres?= <43612178+JuanJTorres11@users.noreply.github.com> Date: Thu, 8 Oct 2020 16:36:01 -0500 Subject: [PATCH 1/3] Add type hints and default args --- project_euler/problem_15/sol1.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/project_euler/problem_15/sol1.py b/project_euler/problem_15/sol1.py index feeb3ddab57a..0dc23ebfc118 100644 --- a/project_euler/problem_15/sol1.py +++ b/project_euler/problem_15/sol1.py @@ -6,32 +6,21 @@ from math import factorial -def lattice_paths(n): +def solution(n:int = 20) -> int: """ Returns the number of paths possible in a n x n grid starting at top left corner going to bottom right corner and being able to move right and down only. - bruno@bruno-laptop:~/git/Python/project_euler/problem_15$ python3 sol1.py 50 - 1.008913445455642e+29 - bruno@bruno-laptop:~/git/Python/project_euler/problem_15$ python3 sol1.py 25 - 126410606437752.0 - bruno@bruno-laptop:~/git/Python/project_euler/problem_15$ python3 sol1.py 23 - 8233430727600.0 - bruno@bruno-laptop:~/git/Python/project_euler/problem_15$ python3 sol1.py 15 - 155117520.0 - bruno@bruno-laptop:~/git/Python/project_euler/problem_15$ python3 sol1.py 1 - 2.0 - - >>> lattice_paths(25) + >>> solution(25) 126410606437752 - >>> lattice_paths(23) + >>> solution(23) 8233430727600 - >>> lattice_paths(20) + >>> solution(20) 137846528820 - >>> lattice_paths(15) + >>> solution(15) 155117520 - >>> lattice_paths(1) + >>> solution(1) 2 """ @@ -46,10 +35,10 @@ def lattice_paths(n): import sys if len(sys.argv) == 1: - print(lattice_paths(20)) + print(solution(20)) else: try: n = int(sys.argv[1]) - print(lattice_paths(n)) + print(solution(n)) except ValueError: print("Invalid entry - please enter a number.") From 1950c3b34473f8105723563e975c7ae614d2fc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Torres?= <43612178+JuanJTorres11@users.noreply.github.com> Date: Thu, 8 Oct 2020 16:52:07 -0500 Subject: [PATCH 2/3] Fixes style --- project_euler/problem_15/sol1.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/project_euler/problem_15/sol1.py b/project_euler/problem_15/sol1.py index 0dc23ebfc118..05b972702a94 100644 --- a/project_euler/problem_15/sol1.py +++ b/project_euler/problem_15/sol1.py @@ -6,22 +6,22 @@ from math import factorial -def solution(n:int = 20) -> int: +def solution(n: int = 20) -> int: """ - Returns the number of paths possible in a n x n grid starting at top left - corner going to bottom right corner and being able to move right and down - only. - - >>> solution(25) - 126410606437752 - >>> solution(23) - 8233430727600 - >>> solution(20) - 137846528820 - >>> solution(15) - 155117520 - >>> solution(1) - 2 + Returns the number of paths possible in a n x n grid starting at top left + corner going to bottom right corner and being able to move right and down + only. + + >>> solution(25) + 126410606437752 + >>> solution(23) + 8233430727600 + >>> solution(20) + 137846528820 + >>> solution(15) + 155117520 + >>> solution(1) + 2 """ n = 2 * n # middle entry of odd rows starting at row 3 is the solution for n = 1, From c39f9ab8373be9d41c609fd2e424c11cdb29f34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Torres?= <43612178+JuanJTorres11@users.noreply.github.com> Date: Thu, 8 Oct 2020 16:57:13 -0500 Subject: [PATCH 3/3] Changes function's name to solution --- project_euler/problem_34/sol1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project_euler/problem_34/sol1.py b/project_euler/problem_34/sol1.py index c19fac5de897..7de7c871db02 100644 --- a/project_euler/problem_34/sol1.py +++ b/project_euler/problem_34/sol1.py @@ -18,7 +18,7 @@ def sum_of_digit_factorial(n: int) -> int: return sum(factorial(int(char)) for char in str(n)) -def compute() -> int: +def solution() -> int: """ Returns the sum of all numbers whose sum of the factorials of all digits @@ -31,4 +31,4 @@ def compute() -> int: if __name__ == "__main__": - print(f"{compute()} = ") + print(f"{solution()} = ")