# Sudoku solution must satisfy all of the following rules:
# Each of the digits 1-9 must occur once in each row.
# Each of the digits 1-9 must occur once in each column.
# Each of the digits 1-9 must occur once in each 3x3 grid.
def is_valid_sudoku_3x3_grid(grid):
if len(grid) != 3 or len(grid[0]) != 3:
return False # Ensure it's a 3x3 grid
seen = set()
for row in grid:
for num in row:
if num < 1 or num > 9 or num in seen:
return False # Invalid if number is out of range or repeated
seen.add(num)
return True # Valid if all numbers 1-9 appear exactly once
grid = [
[5, 3, 4],
[6, 7, 2],
[1, 9, 8]
]
if is_valid_sudoku_3x3_grid(grid):
print("The grid is a valid Sudoku grid!")
else:
print("The grid is NOT a valid Sudoku grid!")
'''
run:
The grid is a valid Sudoku grid!
'''