(bo, num, pos)
| 31 | |
| 32 | |
| 33 | def 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 | |
| 56 | def print_board(bo): |