GUESS #1
guess: atone 2314
Response: nnyyy
GUESS #2
guess: heron 22
Response: ngngy
GUESS #3
Final Guess: venom 1
Response: ggggg
Got Correct Answer!!! venom
Thesaurus Link: https://www.thesaurus.com/e/ways-to-say/most-common-letter/#:~:text=For%20the%20curious%2C%20the%20list,%2C%20R%2C%20H%2C%20and%20L
Most common: e, t, a, i, o, n, s, h, and r. Beginning: t, a, o, d, and w. Ending: e, s, d, and t
def get_5_letter_words():
from word_list import word_list
return word_list
def heuristic(word):
assert word
score = 0
beginning_letters = ["t", "a", "o", "d", "w"]
ending_letters = ["e", "s", "d", "t"]
most_common = ["e", "t", "a", "i", "o", "n", "s", "h", "r"]
extra_special = ["e", "t", "a", "i", "o"]
if word[0] in beginning_letters:
score += 1
if word[-1] in ending_letters:
score += 1
for letter in word:
if word.count(letter) == 1:
if letter in extra_special:
score += 2
elif letter in most_common:
score += 1
return -score
def ranked_words():
return list(sorted(get_5_letter_words(), key=heuristic))
def guess_(ls, final=False):
guess = ls.pop(0)
pre = "Final Guess" if (final or not len(ls)) else "guess"
print(f"{pre}: {guess}", len(ls) + 1)
inp = ""
while len(inp) != 5:
if inp:
print("Error Invalid Input")
inp = input("Response: ")
return guess, inp
def remove_from_ls(ls, condition):
remove_ls = [val for val in ls if condition(val)]
for word in remove_ls:
ls.remove(word)
def counter(word, inp, letter):
count = 0
for char, color in zip(word, inp):
if char == letter and (color == "g" or color == "y"):
count += 1
return count
def parse_input(ls, inp, guess):
gy_counter = {letter: counter(guess, inp, letter) for letter in set(guess)}
yellows = {}
# print(len(ls))
if inp == "ggggg":
print(f"Got Correct Answer!!! {guess}")
return True
for i, (color, letter) in enumerate(zip(inp, guess)):
# print(color)
# print(len(ls))
if color == "g":
# print(ls)
# print(f"Removing all with index {i} != {letter}")
remove_from_ls(ls, lambda word: word[i] != letter)
for word in ls:
assert word[i] == letter
elif color == "y":
# print(f"Removing all with index {i} == {letter}")
remove_from_ls(ls, lambda word: word[i] == letter)
for word in ls:
assert word[i] != letter
# print(f"Removing {letter} count < {gy_counter[letter]}")
remove_from_ls(ls, lambda word: word.count(letter) < gy_counter[letter])
for word in ls:
assert word.count(letter) >= gy_counter[letter]
else:
# print(f"Removing all with index {i} == {letter}")
remove_from_ls(ls, lambda word: word[i] == letter)
for word in ls:
assert word[i] != letter
# print(f"Removing {letter} count > {gy_counter[letter]}")
remove_from_ls(ls, lambda word: word.count(letter) > gy_counter[letter])
for word in ls:
assert word.count(letter) <= gy_counter[letter]
def main():
words = ranked_words()
NUM_TRIES = 6
for attempt in range(1, NUM_TRIES+1):
print(f"GUESS #{attempt}")
guess, response = guess_(words)
valid = parse_input(words, response, guess)
if not len(words) and not valid:
print("ERROR: WORD NOT IN WORD_LIST")
return
elif valid:
return
print(f"Failed to answer in {NUM_TRIES} Turns: :(")
"""
Link: https://www.google.com/search?q=most+used+letters+in+english&rlz=1C5CHFA_enUS810US810&oq=most+used+letters&aqs=chrome.0.0i20i263i512j69i57j0i512l8.6775j0j7&sourceid=chrome&ie=UTF-8
Most common: e, t, a, i, o, n, s, h, and r.
Beginning: t, a, o, d, and w.
Ending: e, s, d, and t
"""
main()
GUESS #1 guess: atone 2314 Response: nnyyy GUESS #2 guess: heron 22 Response: ngngy GUESS #3 Final Guess: venom 1 Response: ggggg Got Correct Answer!!! venom