forked from MIT-Emerging-Talent/ET6-practice-code-review
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Robot Problem + Test Files #23
+170
−2
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bddf02
adding robot.py file as a problem with its corresponding test
reunicorn1 4b33517
Writing the base code for the robot problem
reunicorn1 41a88f5
Writing test cases for the function robot and fixing bugs
reunicorn1 647a4ea
fixing ruff linting errors
reunicorn1 a9dc617
Adding Value error when the variables value is less than 1
reunicorn1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixing ruff linting errors
commit 647a4eafc88927a32551dd636383da262b107a42
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,8 +37,9 @@ def robot_move(cell, rows, cols, memo) -> int: | |
if cell[1] >= cols - 1 or cell[0] >= rows - 1: | ||
return 1 | ||
# otherwise, there's two roads to take, the answer is the sum of both | ||
memo[cell] = robot_move((cell[0] + 1, cell[1]), rows, cols, memo) + \ | ||
robot_move((cell[0], cell[1] + 1), rows, cols, memo) | ||
memo[cell] = robot_move((cell[0] + 1, cell[1]), rows, cols, memo) + robot_move( | ||
(cell[0], cell[1] + 1), rows, cols, memo | ||
) | ||
# we save the answer in the memo for future referance and return it | ||
return memo[cell] | ||
|
||
|
@@ -75,8 +76,4 @@ def robot(rows: int, cols: int) -> int: | |
|
||
# use the helper function robot_move to determine the number of paths | ||
memo = {} | ||
return robot_move((0, 0), rows, cols, memo) # (0, 0) is the initial spot | ||
|
||
|
||
if __name__ == "__main__": | ||
print(robot(23, 12)) | ||
return robot_move((0, 0), rows, cols, memo) # (0, 0) is the initial spot | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of a helper function! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,10 @@ | |
import unittest | ||
from ..robot import robot | ||
|
||
|
||
class TestRobot(unittest.TestCase): | ||
"""Test the robot function""" | ||
|
||
# Standard Cases | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basic case for Single-Cell Grid 1x1 could be added |
||
def test_base_2x2(self): | ||
"""A basic test with a small grid 2x2""" | ||
|
@@ -46,7 +48,7 @@ def test_large_grid(self): | |
self.assertEqual(robot(10, 10), 48620) | ||
|
||
def test_very_large_grid(self): | ||
"""A test for a very largey grid 20x15""" | ||
"""A test for a very large grid 20x15""" | ||
self.assertEqual(robot(20, 15), 818809200) | ||
|
||
# Defensive Cases | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clear Logic