MCPcopy Create free account
hub / github.com/geekcomputers/Python / valid

Function valid

sudoku.py:33–53  ·  view source on GitHub ↗
(bo, num, pos)

Source from the content-addressed store, hash-verified

31
32
33def valid(bo, num, pos):
34 # Check row
35 for i in range(len(bo[0])):
36 if bo[pos[0]][i] == num and pos[1] != i:
37 return False
38
39 # Check column
40 for i in range(len(bo)):
41 if bo[i][pos[1]] == num and pos[0] != i:
42 return False
43
44 # Check box
45 box_x = pos[1] // 3
46 box_y = pos[0] // 3
47
48 for i in range(box_y * 3, box_y * 3 + 3):
49 for j in range(box_x * 3, box_x * 3 + 3):
50 if bo[i][j] == num and (i, j) != pos:
51 return False
52
53 return True
54
55
56def print_board(bo):

Callers 1

solveFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected