-
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
Snow Leopards - Anika and Aria #68
base: master
Are you sure you want to change the base?
Changes from all commits
831494e
d67dc4d
e8a7aa9
83a662d
1181cf3
9e73af9
2120f76
da69141
adf5739
7e0a5dc
5a57461
2ff4c16
e05ed3b
aae761b
4395e35
22fcd6e
4651cc7
5ec2b03
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,5 +1,5 @@ | ||
# AdaGrams | ||
|
||
Snow Leopards - Aria & Anika | ||
## Skills Assessed | ||
|
||
- Following directions and reading comprehension | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,174 @@ | ||
import random | ||
|
||
LETTER_POOL_W_VALUES = { | ||
'A': { | ||
'qty': 9, | ||
'value': 1 | ||
}, | ||
'B': { | ||
'qty': 2, | ||
'value': 3 | ||
}, | ||
'C': { | ||
'qty': 2, | ||
'value': 3 | ||
}, | ||
'D': { | ||
'qty': 4, | ||
'value': 2 | ||
}, | ||
'E': { | ||
'qty': 12, | ||
'value': 1 | ||
}, | ||
'F': { | ||
'qty': 2, | ||
'value': 4 | ||
}, | ||
'G': { | ||
'qty': 3, | ||
'value': 2 | ||
}, | ||
'H': { | ||
'qty': 2, | ||
'value': 4 | ||
}, | ||
'I': { | ||
'qty': 9, | ||
'value' :1 | ||
}, | ||
'J': { | ||
'qty': 1, | ||
'value': 8 | ||
}, | ||
'K': { | ||
'qty': 1, | ||
'value': 5 | ||
}, | ||
'L': { | ||
'qty': 4, | ||
'value': 1 | ||
}, | ||
'M': { | ||
'qty': 2, | ||
'value': 3 | ||
}, | ||
'N': { | ||
'qty': 6, | ||
'value': 1 | ||
}, | ||
'O': { | ||
'qty': 8, | ||
'value': 1 | ||
}, | ||
'P': { | ||
'qty': 2, | ||
'value': 3 | ||
}, | ||
'Q': { | ||
'qty': 1, | ||
'value': 10 | ||
}, | ||
'R': { | ||
'qty': 6, | ||
'value': 1 | ||
}, | ||
'S': { | ||
'qty': 4, | ||
'value': 1 | ||
}, | ||
'T': { | ||
'qty': 6, | ||
'value': 1 | ||
}, | ||
'U': { | ||
'qty': 4, | ||
'value': 1 | ||
}, | ||
'V': { | ||
'qty': 2, | ||
'value': 4 | ||
}, | ||
'W': { | ||
'qty': 2, | ||
'value': 4 | ||
}, | ||
'X': { | ||
'qty': 1, | ||
'value': 8 | ||
}, | ||
'Y': { | ||
'qty': 2, | ||
'value': 4 | ||
}, | ||
'Z': { | ||
'qty': 1, | ||
'value': 10 | ||
} | ||
} | ||
|
||
def draw_letters(): | ||
pass | ||
letters = [] | ||
frequency_of_letters = [] | ||
for letter, frequency in LETTER_POOL_W_VALUES.items(): | ||
letters.append(letter) | ||
frequency_of_letters.append(frequency['qty']) | ||
# random.sample returns a new list containing elements from the population | ||
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. Interesting approach! I appreciate that you added the comment about how the Expanding on that, it's wise to remember that not every language has the same built-in functions, so we should be able to implement this same functionality ourselves. In the projects, we don't ask for any features that we don't think you should be able to write yourself. For drawing a random hand, the only external function that would be "required" is a way to pick a random number (such as randint). At this stage in our coding journeys, it's often more valuable to re-implement things by hand to practice thinking about how to break down and approach the problem at hand, than to use a single library function to solve the problem for us. |
||
# while leaving the original population unchanged. counts controls the | ||
# probability of an element within the sample. in this case, the greater | ||
# the quantity of tiles for a letter, the higher probability that letter | ||
# will be part of the random sample. | ||
random_letters_list = random.sample(letters, counts =\ | ||
frequency_of_letters, k = 10) | ||
return random_letters_list | ||
|
||
def uses_available_letters(word, letter_bank): | ||
pass | ||
copy_letter_bank = letter_bank.copy() | ||
for letter in 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. This works perfectly well! One thing to note is that you're looping through every letter in word on line 127 and then you're using the Rather than using a list of the letters in the hand, could we build a helper data structure (like a dictionary) that could let us look up the number of tiles remaining of each type? If you have a frequency dict and then check if a key is in the dict, then you can leverage the fact that dicts constant time lookup (in contrast to the list's linear time look up). |
||
if letter not in copy_letter_bank: | ||
return False | ||
else: | ||
copy_letter_bank.remove(letter) | ||
return True | ||
|
||
def score_word(word): | ||
pass | ||
score = 0 | ||
for letter in word.upper(): | ||
for k, v in LETTER_POOL_W_VALUES.items(): | ||
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 loop works for sure, but you could save the additional complexity of the inner for-loop and just use the dictionary itself, e.g. score += LETTER_POOL_W_VALUES[letter]["value"] |
||
if k == letter: | ||
score += v["value"] | ||
if 6 < len(word) < 11: | ||
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. 👍 |
||
score += 8 | ||
return score | ||
|
||
def get_highest_word_score(word_list): | ||
pass | ||
# list to store tuples | ||
word_tuple_list = [] | ||
# make a tuple with word, score and length | ||
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 approach does pass the test, but consider the tuple you're returning, which has three elements although the README instructions say to return a tuple with 2 elements (the word and the score). The tests pass because we're testing for the first and second elements of the tuple, e.g. assert the_tuple[0] == "stuff" But if we tested for the length of the tuple or for the explicit tuple, the test would fail, e.g. assert len(best_word) == 2 |
||
# append the tuple to word_tuple_list | ||
for word in word_list: | ||
score = score_word(word) | ||
length = len(word) | ||
word_tuple = (word, score, length) | ||
word_tuple_list.append(word_tuple) | ||
|
||
highest_score_tuple = word_tuple_list[0] | ||
highest_score = word_tuple_list[0][1] | ||
|
||
# element[1] is score in each tuple | ||
# element[2] is len of each word in each tuple | ||
for element in word_tuple_list: | ||
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 approach, it's a bit hard to mentally track the indices referred to, so it might be worth unpacking the elements into variables, in order to improve readability. |
||
# element has score higher than current highest score | ||
if element[1] > highest_score: | ||
highest_score = element[1] | ||
highest_score_tuple = element | ||
# tie breaker | ||
elif element[1] == highest_score: | ||
if element[2] == 10 or highest_score_tuple[2] == 10: | ||
if highest_score_tuple[2] == 10: | ||
continue | ||
else: | ||
highest_score_tuple = element | ||
elif element[2] < highest_score_tuple[2]: | ||
highest_score_tuple = element | ||
return highest_score_tuple |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,26 @@ | |
|
||
from adagrams.game import score_word | ||
|
||
# @pytest.mark.skip | ||
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. No big deal, but since we didn't make any substantive changes to this file, it didn't need to be committed. |
||
def test_score_word_accurate(): | ||
# Assert | ||
assert score_word("A") == 1 | ||
assert score_word("DOG") == 5 | ||
assert score_word("WHIMSY") == 17 | ||
|
||
# @pytest.mark.skip | ||
def test_score_word_accurate_ignores_case(): | ||
# Assert | ||
assert score_word("a") == 1 | ||
assert score_word("dog") == 5 | ||
assert score_word("wHiMsY") == 17 | ||
|
||
# @pytest.mark.skip | ||
def test_score_zero_for_empty(): | ||
# Assert | ||
assert score_word("") == 0 | ||
|
||
# @pytest.mark.skip | ||
def test_score_extra_points_for_seven_or_longer(): | ||
# Assert | ||
assert score_word("XXXXXXX") == 64 | ||
|
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 is an interesting approach to this data structure! A nested dictionary can sometimes be tricky to work with, especially if it's going to be transformed or looped over (with or without nesting) so we'll see how it fares in the code below!