-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cohort_22_Phoenix_Marjana_Khatun #47
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,137 @@ | ||||||||||||||||||||||
import random | ||||||||||||||||||||||
|
||||||||||||||||||||||
def draw_letters(): | ||||||||||||||||||||||
pass | ||||||||||||||||||||||
list_letters = [] | ||||||||||||||||||||||
distribution_of_letters = { | ||||||||||||||||||||||
"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 | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
list_letters = [] | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a duplicate of the variable we declare on line 4, so one of them should be removed. |
||||||||||||||||||||||
while len(list_letters) != 10: | ||||||||||||||||||||||
letters = list(distribution_of_letters.keys()) | ||||||||||||||||||||||
random_letter = random.choice(letters) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this cohort we shared guidance during Unit 1 asking folks to stick to using |
||||||||||||||||||||||
value = distribution_of_letters[random_letter] | ||||||||||||||||||||||
if value > 0: | ||||||||||||||||||||||
distribution_of_letters[random_letter] = value -1 | ||||||||||||||||||||||
list_letters.append(random_letter) | ||||||||||||||||||||||
Comment on lines
+36
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a subtle issue with how we're selecting tiles. We are guaranteed to always get a hand of 10, and we are picking from the full alphabet and ensuring we aren't picking too many of a certain tile however, we aren't taking into account the correct probability of grabbing a particular tile. When we grab a tile, we are picking from the keys of We can get around this a number of ways; one possibility is creating a list containing all of our possible tiles, then remove each tile from this list as we randomly select them. |
||||||||||||||||||||||
return list_letters | ||||||||||||||||||||||
|
||||||||||||||||||||||
def uses_available_letters(word, letter_bank): | ||||||||||||||||||||||
pass | ||||||||||||||||||||||
word = word.upper() | ||||||||||||||||||||||
letters_copy = letter_bank[:] | ||||||||||||||||||||||
for letter in word: | ||||||||||||||||||||||
if letter in letters_copy: | ||||||||||||||||||||||
letters_copy.remove(letter) | ||||||||||||||||||||||
Comment on lines
+48
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a clear and concise solution, but what is the time complexity like? For each letter in How could we use frequency maps to reduce our time complexity? |
||||||||||||||||||||||
else: | ||||||||||||||||||||||
return False | ||||||||||||||||||||||
Comment on lines
+51
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice early exit as soon as we find a letter that isn't in the letter_bank! |
||||||||||||||||||||||
return True | ||||||||||||||||||||||
|
||||||||||||||||||||||
def score_word(word): | ||||||||||||||||||||||
pass | ||||||||||||||||||||||
score = { | ||||||||||||||||||||||
"A" : 1, | ||||||||||||||||||||||
"E" : 1, | ||||||||||||||||||||||
"I" : 1, | ||||||||||||||||||||||
"O" : 1, | ||||||||||||||||||||||
"U" : 1, | ||||||||||||||||||||||
"L" : 1, | ||||||||||||||||||||||
"N" : 1, | ||||||||||||||||||||||
"R" : 1, | ||||||||||||||||||||||
"S" : 1, | ||||||||||||||||||||||
"T" : 1, | ||||||||||||||||||||||
"D" : 2, | ||||||||||||||||||||||
"G" : 2, | ||||||||||||||||||||||
"B" : 3, | ||||||||||||||||||||||
"C" : 3, | ||||||||||||||||||||||
"M" : 3, | ||||||||||||||||||||||
"P" : 3, | ||||||||||||||||||||||
"F" : 4, | ||||||||||||||||||||||
"H" : 4, | ||||||||||||||||||||||
"V" : 4, | ||||||||||||||||||||||
"W" : 4, | ||||||||||||||||||||||
"Y" : 4, | ||||||||||||||||||||||
"K" : 5, | ||||||||||||||||||||||
"J" : 8, | ||||||||||||||||||||||
"X" : 8, | ||||||||||||||||||||||
"Q" :10, | ||||||||||||||||||||||
"Z" :10 | ||||||||||||||||||||||
} | ||||||||||||||||||||||
total_score = 0 | ||||||||||||||||||||||
word = word.upper() | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case it isn't a big deal, but we typically don't want to overwrite our parameter variables since we lose access to the original value. |
||||||||||||||||||||||
for letter in word: | ||||||||||||||||||||||
value = score.get(letter, 0) | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great use of |
||||||||||||||||||||||
total_score += value | ||||||||||||||||||||||
if len(word) >= 7 and len(word) <= 10 : | ||||||||||||||||||||||
total_score += 8 | ||||||||||||||||||||||
return total_score | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
def get_highest_word_score(word_list): | ||||||||||||||||||||||
pass | ||||||||||||||||||||||
highest_word = "" | ||||||||||||||||||||||
highest_score = 0 | ||||||||||||||||||||||
for word in word_list: | ||||||||||||||||||||||
word_score = score_word(word) | ||||||||||||||||||||||
if word_score > highest_score: | ||||||||||||||||||||||
highest_score = word_score | ||||||||||||||||||||||
highest_word = word | ||||||||||||||||||||||
elif word_score == highest_score: | ||||||||||||||||||||||
if len(highest_word) == 10: | ||||||||||||||||||||||
continue | ||||||||||||||||||||||
elif len(word)== 10: | ||||||||||||||||||||||
highest_word = word | ||||||||||||||||||||||
elif len(word)<len(highest_word): | ||||||||||||||||||||||
highest_word = word | ||||||||||||||||||||||
Comment on lines
+103
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't take an action inside the Thinking about long-term code maintenance, if we have to change that code in the future, it goes quicker and is less error-prone when there is only one line to update, rather than several lines that we need to keep in sync. One of many options could be to create variables for the boolean statements: is_new_word_ten = len(word) == 10 and len(highest_word) != 10
is_new_word_smaller = len(word) < len(highest_word) and len(highest_word) != 10
if is_new_word_ten or is_new_word_smaller:
highest_word = word |
||||||||||||||||||||||
return(highest_word,highest_score) | ||||||||||||||||||||||
Comment on lines
+105
to
+109
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reminder about spacing around operators and commas to make statements easier to read quickly.
Suggested change
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice placement of the
distribution_of_letters
structure in the function. It's a tradeoff of visually taking up space in the function so we don't need to worry about changes to the structure between function calls.