From 2e1892e575e18291bae52fcfee0049d0510b201d Mon Sep 17 00:00:00 2001 From: mindaugl Date: Thu, 29 May 2025 21:23:20 +0300 Subject: [PATCH 1/6] Add euler project problem 15 additional solution by explicitly counting the paths. --- project_euler/problem_015/sol2.py | 34 +++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 project_euler/problem_015/sol2.py diff --git a/project_euler/problem_015/sol2.py b/project_euler/problem_015/sol2.py new file mode 100644 index 000000000000..8f54b2316804 --- /dev/null +++ b/project_euler/problem_015/sol2.py @@ -0,0 +1,34 @@ +""" +Problem 15: https://projecteuler.net/problem=15 + +Starting in the top left corner of a 2x2 grid, and only being able to move to +the right and down, there are exactly 6 routes to the bottom right corner. +How many such routes are there through a 20x20 grid? +""" + +from numpy import integer, ones + + +def solution(n: int = 20) -> int: + """ + Solve by explicitly counting the paths with dynamic programming. + + >>> solution(6) + 924 + >>> solution(2) + 6 + >>> solution(1) + 2 + """ + + counts = ones((n + 1, n + 1), dtype=integer) + + for i in range(1, n + 1): + for j in range(1, n + 1): + counts[i][j] = counts[i - 1][j] + counts[i][j - 1] + + return int(counts[n][n]) + + +if __name__ == "__main__": + print(solution()) From 6a6e66218c7d11252c5c3fa3f832137958c5b1be Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Thu, 12 Mar 2026 23:45:15 +0300 Subject: [PATCH 2/6] Update sol2.py --- project_euler/problem_015/sol2.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/project_euler/problem_015/sol2.py b/project_euler/problem_015/sol2.py index 8f54b2316804..629309e15e25 100644 --- a/project_euler/problem_015/sol2.py +++ b/project_euler/problem_015/sol2.py @@ -6,9 +6,6 @@ How many such routes are there through a 20x20 grid? """ -from numpy import integer, ones - - def solution(n: int = 20) -> int: """ Solve by explicitly counting the paths with dynamic programming. @@ -21,13 +18,13 @@ def solution(n: int = 20) -> int: 2 """ - counts = ones((n + 1, n + 1), dtype=integer) + counts = [[1 for _ in range(n + 1)] for _ in range(n + 1)] for i in range(1, n + 1): for j in range(1, n + 1): counts[i][j] = counts[i - 1][j] + counts[i][j - 1] - return int(counts[n][n]) + return counts[n][n] if __name__ == "__main__": From 482d574240070b2f889a36e8fbf960dd46ef0e92 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Thu, 12 Mar 2026 20:45:24 +0000 Subject: [PATCH 3/6] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 4129f9c1a5e2..16cf51a89d02 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -970,6 +970,7 @@ * [Sol2](project_euler/problem_014/sol2.py) * Problem 015 * [Sol1](project_euler/problem_015/sol1.py) + * [Sol2](project_euler/problem_015/sol2.py) * Problem 016 * [Sol1](project_euler/problem_016/sol1.py) * [Sol2](project_euler/problem_016/sol2.py) From 22368789fb70f8bcd79e84a349e53a9c9c1e0e24 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Thu, 12 Mar 2026 20:45:50 +0000 Subject: [PATCH 4/6] updating DIRECTORY.md --- DIRECTORY.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index e301072396fc..ca454bd5fd82 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -469,6 +469,11 @@ ## Geometry * [Geometry](geometry/geometry.py) + * [Graham Scan](geometry/graham_scan.py) + * [Jarvis March](geometry/jarvis_march.py) + * Tests + * [Test Graham Scan](geometry/tests/test_graham_scan.py) + * [Test Jarvis March](geometry/tests/test_jarvis_march.py) ## Graphics * [Bezier Curve](graphics/bezier_curve.py) From 5046bae0a3b3fd46fbb9ffc9272f198ab960e635 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Thu, 12 Mar 2026 23:52:09 +0300 Subject: [PATCH 5/6] Trigger CI From 32082098ad7d174b222a72fadcfdc9fa640d9933 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Mar 2026 20:52:35 +0000 Subject: [PATCH 6/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- project_euler/problem_015/sol2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/project_euler/problem_015/sol2.py b/project_euler/problem_015/sol2.py index 629309e15e25..903095e144ec 100644 --- a/project_euler/problem_015/sol2.py +++ b/project_euler/problem_015/sol2.py @@ -6,6 +6,7 @@ How many such routes are there through a 20x20 grid? """ + def solution(n: int = 20) -> int: """ Solve by explicitly counting the paths with dynamic programming.