-
Notifications
You must be signed in to change notification settings - Fork 0
/
manuel input solve.py
69 lines (61 loc) · 1.76 KB
/
manuel input solve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
def is_repeating(sudoku_grid, location): # checks if given column has same value more than once at given sudoku grid
Y, X, y, x = location
return((len(np.argwhere(sudoku_grid[Y, :, y, :] == sudoku_grid[Y, X, y, x]))) > 1 or
(len(np.argwhere(sudoku_grid[:, X, :, x] == sudoku_grid[Y, X, y, x]))) > 1 or
(len(np.argwhere(sudoku_grid[Y, X, :, :] == sudoku_grid[Y, X, y, x]))) > 1
)
def possible(sudoku_grid, location): # if a place only has one possible number, it is it
Y, X, y, x = location
temp_grid = sudoku_grid
possibles = []
for number in range(1, 10):
temp_grid[Y, X, y, x] = number
if not is_repeating(temp_grid, location):
possibles.append(number)
if len(possibles) == 1:
sudoku_grid[Y, X, y, x] = possibles[0]
m = np.zeros((3, 3, 3, 3)) # Y, X, y, x
m[0, 1, 0, 0] = 2
m[0, 1, 0, 1] = 6
m[0, 2, 0, 0] = 7
m[0, 2, 0, 2] = 1
m[0, 0, 1, 0] = 6
m[0, 0, 1, 1] = 8
m[0, 1, 1, 1] = 7
m[0, 2, 1, 1] = 9
m[0, 0, 2, 0] = 1
m[0, 0, 2, 1] = 9
m[0, 1, 2, 2] = 4
m[0, 2, 2, 0] = 5
m[1, 0, 0, 0] = 8
m[1, 0, 0, 1] = 2
m[1, 1, 0, 0] = 1
m[1, 2, 0, 1] = 4
m[1, 0, 1, 2] = 4
m[1, 1, 1, 0] = 6
m[1, 1, 1, 2] = 2
m[1, 2, 1, 0] = 9
m[1, 0, 2, 1] = 5
m[1, 1, 2, 2] = 3
m[1, 2, 2, 1] = 2
m[1, 2, 2, 2] = 8
m[2, 0, 0, 2] = 9
m[2, 1, 0, 0] = 3
m[2, 2, 0, 1] = 7
m[2, 2, 0, 2] = 4
m[2, 0, 1, 1] = 4
m[2, 1, 1, 1] = 5
m[2, 2, 1, 1] = 3
m[2, 2, 1, 2] = 6
m[2, 0, 2, 0] = 7
m[2, 0, 2, 2] = 3
m[2, 1, 2, 1] = 1
m[2, 1, 2, 2] = 8
temp = m
while len(np.argwhere(m[:, :, :, :] == 0)) > 0 and np.array_equal(temp, m):
empties = np.argwhere(m[:, :, :, :] == 0)
temp = m
for i in empties:
possible(m, i)
print(m)