repl.it
@darkarchon/

ParallelGlamorousWearable

Python

No description

fork
loading
Files
  • main.py
main.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
mat = [
  [9, 1, 3, 6, 4, 2, 5, 7, 8],
  [6, 8, 4, 3, 7, 5, 2, 1, 9],
  [5, 2, 7, 1, 8, 9, 6, 4, 3],
  [2, 7, 5, 4, 3, 8, 1, 9, 6],
  [8, 4, 1, 7, 9, 6, 3, 2, 5],
  [3, 6, 9, 2, 5, 1, 4, 8, 7],
  [4, 3, 6, 8, 1, 7, 9, 5, 2],
  [1, 5, 8, 9, 2, 3, 7, 6, 4],
  [7, 9, 2, 5, 6, 4, 8, 3, 1],
]

bad_sol = [
  [9, 1, 3, 6, 4, 2, 5, 7, 8],
  [6, 8, 4, 3, 7, 5, 2, 1, 9],
  [5, 2, 7, 1, 8, 9, 6, 4, 3],
  [2, 7, 5, 4, 3, 8, 1, 9, 6],
  [8, 4, 1, 7, 9, 6, 3, 2, 5],
  [3, 6, 9, 2, 5, 1, 4, 8, 7],
  [4, 3, 6, 8, 1, 7, 9, 5, 1],
  [1, 5, 8, 9, 2, 3, 7, 6, 4],
  [7, 9, 2, 5, 6, 4, 8, 3, 2],
]

def is_solved(mat):
  return all([
    ((sorted(mat[x]) == list(range(1, 10))) and 
    (sorted((list(zip(*mat)))[x]) == list(range(1, 10))))
     for x in range(9)
  ])

print('mat: {!r}'.format(is_solved(mat)))
print('bad solution: {!r}'.format(is_solved(bad_sol)))
?