Skip to content

Changes functions name, add type hints and default args to problems 15 and 34 #3076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add type hints and default args to problem 15
  • Loading branch information
JuanJTorres11 committed Oct 8, 2020
commit dc03913f399b06ac46cf592ff74256777d46e7f8
45 changes: 16 additions & 29 deletions project_euler/problem_15/sol1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +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)
126410606437752
>>> lattice_paths(23)
8233430727600
>>> lattice_paths(20)
137846528820
>>> lattice_paths(15)
155117520
>>> lattice_paths(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,
# 2, 3,...
Expand All @@ -46,10 +33,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.")