From cc048d5f1931a586f6c57eefe42bd3a40a11ce0a Mon Sep 17 00:00:00 2001 From: Danica Date: Thu, 23 Mar 2023 11:00:42 +0800 Subject: [PATCH 1/4] Pass wave 1 tests --- adagrams/game.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/adagrams/game.py b/adagrams/game.py index 5fb37b11..08d196a5 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -1,6 +1,85 @@ +import random +LETTER_POOL = { + 'A': 9, + 'B': 2, + 'C': 2, + 'D': 4, + 'E': 12, + 'F': 2, + 'G': 3, + 'H': 2, + 'I': 9, + 'J': 1, + 'K': 1, + 'L': 4, + 'M': 2, + 'N': 6, + 'O': 8, + 'P': 2, + 'Q': 1, + 'R': 6, + 'S': 4, + 'T': 6, + 'U': 4, + 'V': 2, + 'W': 2, + 'X': 1, + 'Y': 2, + 'Z': 1 +} + + + +# How do I get a big list with A * 9 etc? +# Why do I need to make a copy of my dictionary? +# letter_pool_list = list(LETTER_POOL) + +# ********* SOLUTION 1 ****************** + def draw_letters(): - pass + big_list = [] + + for letter, letter_quantity in LETTER_POOL.items(): + # loop needs to restart here + big_dict = letter * letter_quantity + for single_char in big_dict: + big_list.append(single_char) + # return big_list + # print(big_list) + +# we want to draw 10 random letters from the big_list + draw_of_10_letters = [] + while len(draw_of_10_letters) < 10: + random_letter = random.choice(big_list) + draw_of_10_letters.append(random_letter) + big_list.remove(random_letter) + print(draw_of_10_letters) + + # for item in big_list: + # random_letter = random.choice(big_list) + # draw_of_10_letters.append(random_letter) + # if len(draw_of_10_letters) == 9: + # print(draw_of_10_letters) + return draw_of_10_letters + +draw_letters() + +# we need to pop() a letter each iteration/draw +# ************ SOLUTION 1 END ****************** + + + +# def letter_frequency(): +# We should only have the values as the quantity of the letters +# How do we establish +# What does distribution mean? +# keys * values? + + # The value of the keys of LETTER_POOL is its quantity + # + +# ******* TEST 2 ********** def uses_available_letters(word, letter_bank): pass From 9e72501edee57606079b838ee3f089be166c4554 Mon Sep 17 00:00:00 2001 From: Danica Date: Fri, 24 Mar 2023 00:01:51 +0800 Subject: [PATCH 2/4] pass wave 2 --- adagrams/game.py | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 08d196a5..13f1240b 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -28,61 +28,35 @@ 'Z': 1 } - - -# How do I get a big list with A * 9 etc? -# Why do I need to make a copy of my dictionary? -# letter_pool_list = list(LETTER_POOL) - -# ********* SOLUTION 1 ****************** - def draw_letters(): big_list = [] - for letter, letter_quantity in LETTER_POOL.items(): - # loop needs to restart here big_dict = letter * letter_quantity for single_char in big_dict: big_list.append(single_char) - # return big_list - # print(big_list) -# we want to draw 10 random letters from the big_list draw_of_10_letters = [] while len(draw_of_10_letters) < 10: random_letter = random.choice(big_list) draw_of_10_letters.append(random_letter) big_list.remove(random_letter) - print(draw_of_10_letters) - - # for item in big_list: - # random_letter = random.choice(big_list) - # draw_of_10_letters.append(random_letter) - # if len(draw_of_10_letters) == 9: - # print(draw_of_10_letters) return draw_of_10_letters draw_letters() -# we need to pop() a letter each iteration/draw -# ************ SOLUTION 1 END ****************** - - - -# def letter_frequency(): -# We should only have the values as the quantity of the letters -# How do we establish -# What does distribution mean? -# keys * values? - - # The value of the keys of LETTER_POOL is its quantity - # - - -# ******* TEST 2 ********** def uses_available_letters(word, letter_bank): - pass + word = word.upper() + for letter in word: + word_count = word.count(letter) + letter_bank_count = letter_bank.count(letter) + if letter not in letter_bank: + return False + if word_count > letter_bank_count: + return False + return True + +# ******* TEST 3 ********** def score_word(word): pass From bad7162edf89b9723badf18e224957e2d7c466d9 Mon Sep 17 00:00:00 2001 From: Danica Date: Fri, 24 Mar 2023 06:19:14 +0800 Subject: [PATCH 3/4] Pass wave 3 --- adagrams/game.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 13f1240b..248f7466 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -56,9 +56,31 @@ def uses_available_letters(word, letter_bank): return False return True -# ******* TEST 3 ********** def score_word(word): - pass + score_chart = { + **dict.fromkeys(["A", "E", "I", "O", "U", "L", "N", "R", "S", "T"], 1), + **dict.fromkeys(["D", "G"], 2), + **dict.fromkeys(["B", "C", "M", "P"], 3), + **dict.fromkeys(["F", "H", "V", "W", "Y"], 4), + **dict.fromkeys(["K"], 5), + **dict.fromkeys(["J", "X"], 8), + **dict.fromkeys(["Q", "Z"], 10), + **dict.fromkeys([""], 0) + } + + word = word.upper() + total_score = 0 + for letter in word: + if word == "": + return False + else: + total_score += score_chart[letter] + if 7 <= len(word) <= 10: + total_score += 8 + return total_score + + +# ******* TEST 4 ********** def get_highest_word_score(word_list): pass \ No newline at end of file From 641a957390653969d4c9942d3b3cb248d6f84f17 Mon Sep 17 00:00:00 2001 From: Danica Date: Sat, 25 Mar 2023 04:47:13 +0800 Subject: [PATCH 4/4] pass wave 4 --- adagrams/game.py | 51 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/adagrams/game.py b/adagrams/game.py index 248f7466..b80a7239 100644 --- a/adagrams/game.py +++ b/adagrams/game.py @@ -80,7 +80,52 @@ def score_word(word): total_score += 8 return total_score - -# ******* TEST 4 ********** def get_highest_word_score(word_list): - pass \ No newline at end of file + + best_words_list = [] + + for word in word_list: + word = word.upper() + score_one_word = score_word(word) + best_words_list.append((word, score_one_word)) + # print(best_words_list) + + for word, score in best_words_list: + if len(word) == 10: + return ((word, score)) + else: + top_score = 0 + best_word = [] + for word, score in best_words_list: + if score > top_score: + top_score = score + best_word = [word] + elif score == top_score: + best_word.append(word) + + short_word = best_word[0] + for word in best_word: + if len(short_word) > len(word): + short_word = word + return short_word, top_score + + + + + + + # max_word_score = max(best_words_list, key=lambda x: x[1]) + # if len(best_words_list) == 1: + # return best_words_list + # else: + # max_score = max(best_words_list, key=lambda x: x[1])[1] + # max_words = [word for word, score in best_words_list if score == max_score] + # if len(max_words) == 1: + # return max(best_words_list, key=lambda x: x[1]) + # else: + # ten_letter_words = [word for word in max_words if len(word) == 10] + # if ten_letter_words: + # return (ten_letter_words[0], max_score) + # else: + # min_length_word = min(max_words, key=lambda x: len(x)) + # return (min_length_word, max_score) \ No newline at end of file