Skip to content

Commit 3c8b6b3

Browse files
authored
Update sudoku.py
1 parent 0b2245a commit 3c8b6b3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

backtracking/sudoku.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,22 @@ def is_safe(grid, row, column, n):
5858
def is_completed(grid):
5959
"""
6060
This function checks if the puzzle is completed or not.
61-
it is completed when all the cells are assigned with a number(not zero)
62-
and There is no repeating number in any column, row or 3x3 subgrid.
61+
it is completed when all the cells are assigned with a non-zero number.
62+
63+
>>> is_completed([[0]])
64+
False
65+
>>> is_completed([[1]])
66+
True
67+
>>> is_completed([[1, 2], [0, 4]])
68+
False
69+
>>> is_completed([[1, 2], [3, 4]])
70+
True
71+
>>> is_completed(initial_grid)
72+
False
73+
>>> is_completed(no_solution)
74+
False
6375
"""
64-
return all(cell != 0 for cell in row for row in grid)
65-
76+
return all(all(cell != 0 for cell in row) for row in grid)
6677

6778
def find_empty_location(grid):
6879
"""

0 commit comments

Comments
 (0)