repl.it
@anonymous/

UnwieldyFlawedWallaby

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
35
36
from collections import Counter

tab = [None] * 11*11

def split(t):
    return [t[11*i:11*i+11] for i in range(11)]

not_none = lambda x: x is not None

calls_counter = 0
inconsistencies_counter = 0

def solve(t):
    global calls_counter
    global inconsistencies_counter
    calls_counter += 1
    cnt = Counter(sum(filter(not_none, row))
        for row in split(t)
            if len(list(filter(not_none, row))) == 11)
    if len(cnt) == 22:
        # OK
        return t
    if len(cnt) > 0 and cnt.most_common(1)[0][1]:
        # Inconsistency
        inconsistencies_counter += 1
        return None
    for val in [-1, 0, 1]:
        tt = t[:]
        tt[t.index(None)] = val
        res = solve(tt)
        if res:
            return res
    return None

print(solve(tab))
print(calls_counter, inconsistencies_counter)