-
Notifications
You must be signed in to change notification settings - Fork 6
/
ordla.py
executable file
·71 lines (69 loc) · 2.11 KB
/
ordla.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
70
71
def add(word, verdict):
temp = {}
for idx in range(len(word)):
if verdict[idx] != 'X':
if word[idx] not in temp:
temp[word[idx]] = 0
temp[word[idx]] += 1
for k in temp:
if k not in freq:
freq[k] = set(range(len(word)))
freq[k] -= set(range(temp[k]))
for idx in range(len(word)):
if verdict[idx] == 'X':
if word[idx] in temp:
freq[word[idx]] = {temp[word[idx]]}
else:
freq[word[idx]] = {0}
for idx in range(len(word)):
if verdict[idx] == '/':
if word[idx] not in kb:
kb[word[idx]] = set(range(len(word)))
kb[word[idx]] -= {idx}
for idx in range(len(word)):
if verdict[idx] == 'O':
if word[idx] not in kb2:
kb2[word[idx]] = set()
kb2[word[idx]].add(idx)
for idx in range(len(word)):
if verdict[idx] == 'X' and word[idx] not in kb and word[idx] not in kb2:
illegal.add(word[idx])
def verify(check):
kb2c = {}
for k in kb2:
kb2c[k] = kb2[k].copy()
for idx in range(len(check)):
if check[idx] in illegal:
return
try:
kb2c[check[idx]].remove(idx)
if not kb2c[check[idx]]:
del kb2c[check[idx]]
except:
if check[idx] in kb and idx not in kb[check[idx]]:
return
freq2 = {}
for k in check:
if k not in freq2:
freq2[k] = 0
freq2[k] += 1
for k in freq2:
if k in freq and freq2[k] not in freq[k]:
return
for k in freq:
if k in freq2:
if min(freq[k]) > freq2[k]:
return
elif min(freq[k]) > 0:
return
if not kb2c:
possible.append(check)
from random import *
N = int(input()); W = [input() for _ in range(N)]
kb, kb2, freq = {}, {}, {}; illegal = set()
while W:
print(word:=choice(W)); W.remove(word); verdict = input(); add(word, verdict)
if verdict == 'O'*5: exit(0)
possible = []
for w in W: verify(w)
W = possible