Skip to content
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

Fix #4

Open
wants to merge 9 commits into
base: fix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode/settings.json
79 changes: 0 additions & 79 deletions a.py

This file was deleted.

8 changes: 8 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: cs197
channels:
- defaults
dependencies:
- python=3.9
- tqdm
- numpy
prefix: /Users/ethan/opt/anaconda3/envs/cs197
16 changes: 9 additions & 7 deletions number_of_ways.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ def numberOfWays(startPos: int, endPos: int, k: int) -> int:
perform exactly k steps.
"""
# start with path of length 1
paths = [startPos]
paths = [[startPos]]

# loop k times
for i in tqdm(range(k)):
for path in paths:
new_path = path.copy()
for _ in range(len(paths)):
new_path = paths.pop(0)
last_position = new_path[-1]

# exist fast if not going to make to end
if endPos - last_position > (k - i - 1):
if endPos - last_position > (k - i):
continue
# path that goes to the left
new_path_left = new_path + [last_position - 1]

# path that goes to the right
new_path_right = new_path + [last_position - 1]
new_path_right = new_path + [last_position + 1]

# add paths to the left and right
paths.append(new_path_left)
Expand All @@ -40,9 +40,11 @@ def numberOfWays(startPos: int, endPos: int, k: int) -> int:
num_ways = 0
for path in paths:
if path[-1] == endPos:
new_ways += 1
num_ways += 1
return num_ways

##adding some bs line here


def test_number_of_ways():
"""
Expand All @@ -57,7 +59,7 @@ def test_number_of_ways():
- 1 -> 0 -> 1 -> 2.
It can be proven that no other way is possible, so we return 3.
"""
numberOfWays(1, 2, 3)
print(numberOfWays(1, 2, 3))

if __name__ == "__main__":
test_number_of_ways()