63 lines
No EOL
1.4 KiB
Python
63 lines
No EOL
1.4 KiB
Python
CORRECT_WORD = "TODAYS_WORD"
|
|
|
|
"""
|
|
2 = correct (green)
|
|
1 = diff place (yellow)
|
|
0 = nowhere (gray)
|
|
"""
|
|
|
|
MATRIX = """
|
|
02020
|
|
00000
|
|
00200
|
|
20002
|
|
02220
|
|
00000
|
|
""".strip().split("\n")
|
|
|
|
assert len(MATRIX) == 6
|
|
assert all([m != "22222" for m in MATRIX[0:5]]) # if you solve the word early you dont get any more guesses
|
|
|
|
words = open("words.txt", "r").read().strip().split("\n")
|
|
assert CORRECT_WORD.lower() in words
|
|
|
|
def matches(given, correct, mask):
|
|
if len(given) != len(correct) or len(mask) != len(correct):
|
|
return False
|
|
|
|
n = len(given)
|
|
result = ['0'] * n
|
|
correct_counts = {}
|
|
|
|
for i in range(n):
|
|
if given[i] == correct[i]:
|
|
result[i] = '2'
|
|
else:
|
|
correct_counts[correct[i]] = correct_counts.get(correct[i], 0) + 1
|
|
|
|
for i in range(n):
|
|
if result[i] == '2':
|
|
continue
|
|
if given[i] in correct_counts and correct_counts[given[i]] > 0:
|
|
result[i] = '1'
|
|
correct_counts[given[i]] -= 1
|
|
|
|
return ''.join(result) == mask
|
|
|
|
final_words = []
|
|
|
|
for i in range(len(MATRIX)):
|
|
mask = MATRIX[i]
|
|
|
|
found = False
|
|
for word in words:
|
|
if word not in final_words and matches(word, CORRECT_WORD.lower(), mask):
|
|
final_words.append(word)
|
|
found = True
|
|
break
|
|
|
|
if not found:
|
|
print(f"Unsolvable for {i}")
|
|
exit(1)
|
|
|
|
print(*[final_word.upper() for final_word in final_words], sep="\n") |