Skip to content
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

Tigers - Reyna + Misha #79

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

reynamdiaz
Copy link

it's game time

Copy link

@spitsfire spitsfire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job working together, Reyna and Misha!

Here are a few things to consider for future projects that I've detailed below in your code:

  • There were a few places in Wave 1 that the logic was incomplete. Unfortunately, the tests didn't quite catch it.
  • Careful creating variables that aren't used. There were a few places where a variable was created and modified. But then that variable was never used to compare or calculate the final output.

If you have any questions about the feedback, please reach out to me!

def uses_available_letters(word, letter_bank):
pass
for letter in letters_not_drawn:
if letter not in letters_drawn and len(letters_drawn) < 10:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm does this mean that the list of letters_drawn will never have duplicate letters? Plenty of words need to use the same letters. That's why the LETTER_POOL pull has values that represent how many of each letter can be pulled.

Instead of checking letter not in letters_drawn, we should check whether or not the letter has a quantity greater than 0 to still draw from.


def uses_available_letters(word, letter_bank):
pass
for letter in letters_not_drawn:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could combine the for loop and if statement in one using a while loop. Consider:

while len(letters_draw) < 10:
    # randomly select a letter
    # append to letters_drawn if that letter has any quantity left
    # the rest of your code

But what letter do we draw? Well, it's supposed to be random every time. Instead of running a for loop from start to finish, how can we randomly select a key or an index position? (This may take some Googling)

Comment on lines +23 to +31
for letter in word:
if letter in letter_bank and word.count(letter) <= letter_bank.count(letter):
word_dict[letter] = True
letter_count += 1
is_valid = True
elif not letter in letter_bank:
word_dict[letter] = False
is_valid = False
return is_valid

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of the word_dict and letter_count altogether! Both are created and updated, but then they aren't used anywhere to calculate our final result.

Secondly, there's a logic error that the tests didn't pick up on. Let's take the word "ALABAMA" for example. Based on this function:

letter_bank = ["F","A","B","D","A","C","C","L","M","N"]
uses_available_letters("ALABAMA", letter_bank)

it returns True, which it shouldn't. What's causing this? Well, let's take "A" through your conditionals.

if letter in letter_bank and word.count(letter) <= letter_bank.count(letter) 4<= 2 so, no this doesn't execute.

elif not letter in letter_bank "A" is in the letter_bank, so this doesn't execute either.

What can we add to this function to fix this?

word_dict[letter] = False
is_valid = False
return is_valid

def score_word(word):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 good job!

Comment on lines +63 to +64
shortest_word = min(highest_scoring_words, key=len)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 nice job using max and min so effectively!

score += key
if len(word) >= 7:
score += 8
return score

def get_highest_word_score(word_list):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

for letter in letters_not_drawn:
if letter not in letters_drawn and len(letters_drawn) < 10:
letters_drawn.append(letter)
letter_count += 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look like we are using this variable anywhere. Let's get rid of it!

Comment on lines +23 to +24
for letter in word:
if letter in letter_bank and word.count(letter) <= letter_bank.count(letter):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are only just learning about Big O and a function's time and space complexity, but let's explore how we can make this more efficient.

Right now we have a loop inside a loop (if...in has a loop under the hood). That makes the code O(n^2). Consider calculating a frequency map of the letters before entering the for loop on line 23. Building a frequency map is a linear operation aka O(n), but we could look up the letters in constant time aka O(1) with a frequency map (if letter in dictionary versus if letter in list).

That's very technical, but to summarize: using a dictionary to look up each letter in the word and subtracting from the dictionary would be more time efficient than checking if the letter is in the letter_bank list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants