-
Notifications
You must be signed in to change notification settings - Fork 89
Tigers- Selam Chaka #60
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
base: master
Are you sure you want to change the base?
Changes from all commits
70aea46
39dc166
7731788
89d5e07
44957ea
3f3ed4a
829880b
c97227d
fb8d2e4
16412e3
0ae543f
a8df5ca
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,149 @@ | ||
def draw_letters(): | ||
pass | ||
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 | ||
} | ||
|
||
SCORE_CHART = { | ||
'A': 1, | ||
'B': 3, | ||
'C': 3, | ||
'D': 2, | ||
'E': 1, | ||
'F': 4, | ||
'G': 2, | ||
'H': 4, | ||
'I': 1, | ||
'J': 8, | ||
'K': 5, | ||
'L': 1, | ||
'M': 3, | ||
'N': 1, | ||
'O': 1, | ||
'P': 3, | ||
'Q': 10, | ||
'R': 1, | ||
'S': 1, | ||
'T': 1, | ||
'U': 1, | ||
'V': 4, | ||
'W': 4, | ||
'X': 8, | ||
'Y': 4, | ||
'Z': 10 | ||
} | ||
|
||
def draw_letters(): | ||
letter_freq = {} | ||
random_letters=[] | ||
selected_letters =[] | ||
while len(random_letters) < 26: | ||
r = random.choice(list(LETTER_POOL.keys())) | ||
random_letters.append(r) | ||
for letter in random_letters: | ||
if letter in letter_freq: | ||
letter_freq[letter] += 1 | ||
else: | ||
letter_freq[letter] = 1 | ||
if letter_freq[letter] <= LETTER_POOL[letter]: | ||
selected_letters.append(letter) | ||
return (selected_letters[0:10]) | ||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
word_str = "" | ||
temp_word = "" | ||
letter_bank_dic = {} | ||
word_dic ={} | ||
|
||
for letter in word: | ||
if str.upper(letter) in letter_bank: | ||
temp_word += letter | ||
word_str += str.upper(letter) | ||
for letter in letter_bank: | ||
if letter in letter_bank_dic: | ||
letter_bank_dic[str.upper(letter)] += 1 | ||
else: | ||
letter_bank_dic[str.upper(letter)] = 1 | ||
for letter in word_str: | ||
if letter in word_dic: | ||
word_dic[str.upper(letter)] += 1 | ||
else: | ||
word_dic[str.upper(letter)] = 1 | ||
if word_dic[letter] > letter_bank_dic[letter]: | ||
return False | ||
elif temp_word != word: | ||
return False | ||
elif temp_word == word: | ||
return True | ||
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. I see exactly what y'all were doing here. The problem is that you are making a variety of extra dictionaries and strings that just aren't necessary. In cases like this, it would be much better to make a deep copy of the letter_bank. From there, you can simply manipulate your copy. The process would be as follows:
This will take into account multiples of the same 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. I see exactly what y'all were doing here. The problem is that you are making a variety of extra dictionaries and strings that just aren't necessary. In cases like this, it would be much better to make a deep copy of the letter_bank. From there, you can simply manipulate your copy. The process would be as follows:
This will take into account multiples of the same letter! |
||
|
||
def score_word(word): | ||
pass | ||
if word == "": | ||
return 0 | ||
score_word = 0 | ||
upper_word = str.upper(word) | ||
|
||
for letter in upper_word: | ||
for key, value in SCORE_CHART.items(): | ||
if letter == key: | ||
score_word += value | ||
|
||
if len(word) in range(7, 11): | ||
score_word += 8 | ||
|
||
return score_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. This looks great! It's a simple and effective implementation of the score method! |
||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
highest_word = [] | ||
highest_value = 0 | ||
tie_word = [] | ||
for word in word_list: | ||
word_score = score_word(word) | ||
if word_score > highest_value: | ||
highest_word = word | ||
highest_value = word_score | ||
tie_word = [highest_word] | ||
elif word_score == highest_value: # tie case | ||
tie_word.append(word) | ||
|
||
if len(tie_word) > 1 : | ||
if len(tie_word[0]) > len(tie_word[1]) and len(tie_word[0])==10 : | ||
return (tie_word[0], highest_value) | ||
elif len(tie_word[0]) < len(tie_word[1]) and len(tie_word[1])!=10 : | ||
return (tie_word[0], highest_value) | ||
elif len(tie_word[0]) == len(tie_word[1]): | ||
return(tie_word[0], highest_value) | ||
else: | ||
return(tie_word[1], highest_value) | ||
|
||
return (highest_word, highest_value) | ||
|
||
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. Once again, you are creating several extra lists that we don't necessarily need. This works and is a great first pass, but we could definitely pare it down a bit! One implementation would have been to have a tuple that just holds the highest scoring word and the highest score. From there, we can do the following:
This really just avoids having to write a tie_word list. We can kind of figure out what the highest word in place. |
||
|
||
|
||
|
||
|
||
|
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.
This looks good, overall but remember that it is not accounting for the different probabilities of each letter! We could take that into account by creating a collection of some sort that holds every possible value (12 E's, 9 A's, etc) and then making our selections from that collection and removing them as they are picked!