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

Robot Problem + Test Files #23

Merged
merged 5 commits into from
Jan 6, 2025
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
Prev Previous commit
Next Next commit
fixing ruff linting errors
reunicorn1 committed Jan 4, 2025
commit 647a4eafc88927a32551dd636383da262b107a42
11 changes: 4 additions & 7 deletions solutions/robot.py
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]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear Logic


@@ -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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of a helper function!

4 changes: 3 additions & 1 deletion solutions/tests/test_robot.py
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
Copy link

Choose a reason for hiding this comment

The 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