-
Notifications
You must be signed in to change notification settings - Fork 89
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
Carmen and Nina - C18 Cheetahs #78
base: master
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,126 @@ | ||||||||||
import random | ||||||||||
|
||||||||||
def draw_letters(): | ||||||||||
pass | ||||||||||
# Import random - assign the randomized number to the index | ||||||||||
# "bag" of letters will be a dictionary as shown below | ||||||||||
# hand will be a list | ||||||||||
# | A : 9 | N : 6 | | ||||||||||
# | B : 2 | O : 8 | | ||||||||||
# | C : 2 | P : 2 | | ||||||||||
# | D : 4 | Q : 1 | | ||||||||||
# | E : 12 | R : 6 | | ||||||||||
# | F : 2 | S : 4 | | ||||||||||
# | G : 3 | T : 6 | | ||||||||||
# | H : 2 | U : 4 | | ||||||||||
# | I : 9 | V : 2 | | ||||||||||
# | J : 1 | W : 2 | | ||||||||||
# | K : 1 | X : 1 | | ||||||||||
# | L : 4 | Y : 2 | | ||||||||||
# | M : 2 | Z : 1 | | ||||||||||
bag_of_letters_dict = { | ||||||||||
'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 | ||||||||||
} | ||||||||||
bag_of_letters_list = [] | ||||||||||
for key, value in bag_of_letters_dict.items(): | ||||||||||
for letter in range(value): | ||||||||||
bag_of_letters_list.append(key) | ||||||||||
Comment on lines
+49
to
+51
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 way to generate the bag of letters! |
||||||||||
|
||||||||||
hand = [] | ||||||||||
|
||||||||||
while len(hand) < 10: | ||||||||||
for letter in bag_of_letters_list: | ||||||||||
hand.append(letter) | ||||||||||
letter_of_index = bag_of_letters_list.index(letter) | ||||||||||
bag_of_letters_list.pop(letter_of_index) | ||||||||||
break | ||||||||||
return hand | ||||||||||
Comment on lines
+55
to
+61
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 really close to a working solution, but it will always produce the same list of letters (['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B']). The primary issue is that there is no randomization in this solution. The while loop will run 10 times, and each time through the loop, the inner loop runs once. The inner loop will start with the first letter in |
||||||||||
|
||||||||||
def uses_available_letters(word, letter_bank): | ||||||||||
pass | ||||||||||
true_false = [] | ||||||||||
word = word.upper() | ||||||||||
word_list = [] | ||||||||||
|
||||||||||
for letter in word: | ||||||||||
word_list.append(letter) | ||||||||||
if letter in letter_bank and word_list.count(letter) == letter_bank.count(letter): | ||||||||||
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 passes our tests, but there is a bug here. If
Suggested change
|
||||||||||
true_false.append(True) | ||||||||||
else: | ||||||||||
true_false.append(False) | ||||||||||
Comment on lines
+72
to
+73
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 possible short circuit here. If the code ever reaches this point, the word is not valid, so it's possible to just return
Suggested change
|
||||||||||
if False in true_false: | ||||||||||
return False | ||||||||||
else: | ||||||||||
return True | ||||||||||
|
||||||||||
def score_word(word): | ||||||||||
pass | ||||||||||
scoreboard = { | ||||||||||
1 : "A, E, I, O, U, L, N, R, S, T", | ||||||||||
2 : "D, G", | ||||||||||
3 : "B, C, M, P", | ||||||||||
4 : "F, H, V, W, Y", | ||||||||||
5 : "K", | ||||||||||
8 : "J, X", | ||||||||||
10 : "Q, Z" | ||||||||||
} | ||||||||||
word = word.upper() | ||||||||||
#- If the length of the word is 7, 8, 9, or 10, | ||||||||||
# then the word gets an additional 8 points | ||||||||||
score = 0 | ||||||||||
for letter in word: | ||||||||||
for key, value in scoreboard.items(): | ||||||||||
if letter in value: | ||||||||||
score += key | ||||||||||
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 nominally an O(n) solution, but only because the inner loop is not growing in relation to the input size. For every letter in |
||||||||||
if len(word) > 6: | ||||||||||
score += 8 | ||||||||||
return score | ||||||||||
|
||||||||||
|
||||||||||
|
||||||||||
def get_highest_word_score(word_list): | ||||||||||
pass | ||||||||||
tuple = () | ||||||||||
winner_score = 0 | ||||||||||
word_score = {} | ||||||||||
winner_word = '' | ||||||||||
for word in word_list: | ||||||||||
word_score[word] = score_word(word) | ||||||||||
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. 👍 |
||||||||||
for key, value in word_score.items(): | ||||||||||
if value > winner_score: | ||||||||||
winner_score = value | ||||||||||
winner_word = key | ||||||||||
if value == winner_score: | ||||||||||
if len(key) < len(winner_word): | ||||||||||
winner_word = key | ||||||||||
|
||||||||||
tuple = (winner_word, winner_score) | ||||||||||
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 progress on this wave! This algorithm works well to find the top score when there are no ties. |
||||||||||
return tuple | ||||||||||
# winner = () | ||||||||||
# word_score = {} | ||||||||||
# for word in word_list: | ||||||||||
# word_score[word] = score_word(word) | ||||||||||
# for key, value in word_score.items(): | ||||||||||
# winner + max(value),key | ||||||||||
# return winner |
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.
Fantastic plan!