From a640fb0ae65b009e1c1f0ce8c3fca7c9f409f9c4 Mon Sep 17 00:00:00 2001 From: Adam Blank <blank@caltech.edu> Date: Wed, 16 Oct 2024 15:58:03 +0000 Subject: [PATCH] autocommit --- 06/wordle1.py | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/06/wordle1.py b/06/wordle1.py index 0c34683..9535601 100644 --- a/06/wordle1.py +++ b/06/wordle1.py @@ -19,15 +19,54 @@ def is_valid_guess(guess: str): def how_many_exact_matches(word1: str, word2: str) -> int: - ... + count: int = 0 + for i in range(len(word1)): + if word1[i] == word2[i]: + count += 1 + return count + + +def get_counts_of_letters_1(word: str) -> dict[str, int]: + d: dict[str, int] = {} + for letter in UPPERCASE_LETTERS: + count: int = 0 + for c in word: + if c == letter: + count += 1 + d[letter] = count + return d def get_counts_of_letters(word: str) -> dict[str, int]: - ... + d: dict[str, int] = {} + for c in word: + if c in d: + d[c] = d[c] + 1 + else: + d[c] = 0 + 1 + return d def how_many_overall_matches(guess: str, answer: str) -> int: - ... + guess_count = get_counts_of_letters(guess) + answer_count = get_counts_of_letters(answer) + + count: int = 0 + for letter in UPPERCASE_LETTERS: + count_a: int = 0 + if letter in guess_count: + count_a = guess_count[letter] + + count_b: int = 0 + if letter in answer_count: + count_b = answer_count[letter] + + count += min(count_a, count_b) + + return count + + +print(how_many_overall_matches("AAB", "BAC")) def play_wordle_game(): -- GitLab