| 83 | |
| 84 | |
| 85 | def possible(bo, pos, num): |
| 86 | # checking row |
| 87 | for i in range(len(bo[0])): |
| 88 | if bo[pos[0]][i] == num and pos[1] != i: |
| 89 | # not possible |
| 90 | return False |
| 91 | |
| 92 | # checking column |
| 93 | for i in range(len(bo)): |
| 94 | if bo[i][pos[1]] == num and pos[0] != i: |
| 95 | # not possible |
| 96 | return False |
| 97 | |
| 98 | # checking square |
| 99 | box_x = pos[1] // 3 |
| 100 | box_y = pos[0] // 3 |
| 101 | |
| 102 | for i in range(box_y * 3, box_y * 3 + 3): # row |
| 103 | for j in range(box_x * 3, box_x * 3 + 3): # col |
| 104 | if bo[i][j] == num and (i, j) != pos: |
| 105 | # not possible number |
| 106 | return False |
| 107 | # possible number |
| 108 | return True |
| 109 | |
| 110 | |
| 111 | def next_empty(bo): |