-
-
Notifications
You must be signed in to change notification settings - Fork 46.9k
Docstrings and formatting improvements #2418
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
Changes from 3 commits
b6d37bf
17e0c8a
707f62a
f405493
36b0913
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,13 +1,13 @@ | ||||||
def solve_maze(maze: list) -> bool: | ||||||
""" | ||||||
This method solves rat in maze algorithm. | ||||||
In this problem we have n by n matrix and we have start point and end point | ||||||
we want to go from source to distination. In this matrix 0 are block paths | ||||||
1 are open paths we can use. | ||||||
This method solves the "rat in maze" problem. | ||||||
In this problem we have some n by n matrix, a start point and an end point. | ||||||
We want to go from the start to the end. In this matrix zeroes represent walls | ||||||
and ones paths we can use. | ||||||
Parameters : | ||||||
maze(2D matrix) : maze | ||||||
Returns: | ||||||
Return: True is maze has a solution or False if it does not. | ||||||
Return: True if the maze has a solution or False if it does not. | ||||||
>>> maze = [[0, 1, 0, 1, 1], | ||||||
... [0, 0, 0, 0, 0], | ||||||
... [1, 0, 1, 0, 1], | ||||||
|
@@ -47,13 +47,13 @@ def solve_maze(maze: list) -> bool: | |||||
... [0, 1, 0], | ||||||
... [1, 0, 0]] | ||||||
>>> solve_maze(maze) | ||||||
Solution does not exists! | ||||||
Solution does not exist! | ||||||
False | ||||||
|
||||||
>>> maze = [[0, 1], | ||||||
... [1, 0]] | ||||||
>>> solve_maze(maze) | ||||||
Solution does not exists! | ||||||
Solution does not exist! | ||||||
False | ||||||
""" | ||||||
size = len(maze) | ||||||
|
@@ -63,16 +63,16 @@ def solve_maze(maze: list) -> bool: | |||||
if solved: | ||||||
print("\n".join(str(row) for row in solutions)) | ||||||
else: | ||||||
print("Solution does not exists!") | ||||||
print("Solution does not exist!") | ||||||
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.
Suggested change
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. I would raise an exception but that is a personal choice. |
||||||
return solved | ||||||
|
||||||
|
||||||
def run_maze(maze, i, j, solutions): | ||||||
""" | ||||||
This method is recursive method which starts from i and j | ||||||
and goes with 4 direction option up, down, left, right | ||||||
if path found to destination it breaks and return True | ||||||
otherwise False | ||||||
This method is recursive : it starts from (i, j) | ||||||
and goes in one of these four directions: up, down, left, right | ||||||
if a path is found to destination it breaks and returns True | ||||||
otherwise it returns False | ||||||
Parameters: | ||||||
maze(2D matrix) : maze | ||||||
i, j : coordinates of matrix | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,8 @@ def prime_implicant_chart(prime_implicants, binary): | |
>>> prime_implicant_chart(['0.00.01.5'],['0.00.01.5']) | ||
[[1]] | ||
""" | ||
chart = [[0 for x in range(len(binary))] for x in range(len(prime_implicants))] | ||
chart = [[0 for x in range(len(binary))] | ||
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. My sense is that psf/black will undo this change. |
||
for x in range(len(prime_implicants))] | ||
for i in range(len(prime_implicants)): | ||
count = prime_implicants[i].count("_") | ||
for j in range(len(binary)): | ||
|
@@ -146,7 +147,7 @@ def main(): | |
minterms = [ | ||
int(x) | ||
for x in input( | ||
"Enter the decimal representation of Minterms 'Spaces Seprated'\n" | ||
"Enter the decimal representation of Minterms 'Spaces Separated'\n" | ||
).split() | ||
] | ||
binary = decimal_to_binary(no_of_variable, minterms) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,14 @@ def new_generation(cells: List[List[int]], rule: List[int], time: int) -> List[i | |
next_generation = [] | ||
for i in range(population): | ||
# Get the neighbors of each cell | ||
left_neighbor = 0 if i == 0 else cells[time][i - 1] # special: leftmost cell | ||
right_neighbor = 0 if i == population - 1 else cells[time][i + 1] # rightmost | ||
# Handle neighbours outside bounds by using 0 as their value | ||
left_neighbor = 0 if i == 0 else cells[time][i - 1] | ||
right_neighbor = 0 if i == population - 1 else cells[time][i + 1] | ||
# Define a new cell and add it to the new generation | ||
situation = 7 - int(f"{left_neighbor}{cells[time][i]}{right_neighbor}", 2) | ||
situation = 7 - int( | ||
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. My sense is that psf/black will undo this change. |
||
f"{left_neighbor}{cells[time][i]}{right_neighbor}", | ||
2 | ||
) | ||
next_generation.append(rule[situation]) | ||
return next_generation | ||
|
||
|
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.