From 18e9c6a1518d05b828bbfe26562caca75c61b547 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Tue, 18 Jan 2022 19:36:57 +0100 Subject: [PATCH] play_solve --- play.py | 11 +++++++---- solve.py | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/play.py b/play.py index 3cd2996..6440960 100644 --- a/play.py +++ b/play.py @@ -22,6 +22,12 @@ def build_letter_hint(guess, word): word_break[first_index] = BLANK return ''.join(letters_hints) +def build_non_letter_hint(guess, word): + non_letters_hints = '' + for letter in guess: + if letter not in word and letter not in non_letters_hints: + non_letters_hints += letter + return non_letters_hints def main_loop(): word = random.choice([w for w in cat_words()]) @@ -31,10 +37,7 @@ def main_loop(): guess = input("Guess: ") if len(guess) != 5 and not all([x.islower() for x in guess]): print("ERROR: {}".format(PLAY_INSTRUCTIONS)) - non_letters_hints = '' - for letter in guess: - if letter not in word and letter not in non_letters_hints: - non_letters_hints += letter + non_letters_hints = build_non_letter_hint(guess, word) letters_hints = build_letter_hint(guess, word) print("Non-letters: {}".format(non_letters_hints)) print("Letters: {}".format(letters_hints)) diff --git a/solve.py b/solve.py index 347e14e..16e2886 100644 --- a/solve.py +++ b/solve.py @@ -147,6 +147,7 @@ def test(): assert [w for w in round_words('', ['----y'], ['y----'], dictionary=['slyly'])] == ['slyly'] assert [w for w in round_words('', ['---yy'], ['y----'], dictionary=['slyyy'])] == ['slyyy'] assert [w for w in round_words('', ['---yy'], ['-----'], dictionary=['slyyy'])] == ['slyyy'] + assert [w for w in round_words('', ['-y---'], ['--y--'], dictionary=['sysys'])] == ['sysys'] def main():