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

amethyst-Raina #106

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

amethyst-Raina #106

wants to merge 2 commits into from

Conversation

Rainacam12
Copy link

No description provided.

Comment on lines +39 to +40
letter_pool_keys = letter_pool.keys()
letter_list = list(letter_pool_keys)

Choose a reason for hiding this comment

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

We could shorten this into one line by doing the following:

letter_pool = list(letter_pool.keys())

letter_pool_keys = letter_pool.keys()
letter_list = list(letter_pool_keys)
if len(letter_list) > 0:
letter = random.choice(letter_list)

Choose a reason for hiding this comment

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

So, you handled the constraints of the weights correctly (making sure that you don't have too many instances of one letter in the list). However, with letter = random.choice(letter_list) all the letters have an equal chance of being chosen, whereas we want certain letters to be have a greater chance (E having a value of 12 should be 12x as likely to be chosen than Z being that it has only value of 1. We can do that with an implementation like this:

letters = []
for letter in LETTER_POOL:
    letters += letter * LETTER_POOL[letter]

This will create a list of letters where each letter will be added to the list however many times that correlates with its value pair. 'S' * 4 => ['S', 'S', 'S', 'S']


def uses_available_letters(word, letter_bank):
pass
# create var to count occurrences of each letter in word
word = word.upper()

Choose a reason for hiding this comment

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

One thing that we usually never want to do is reassign an argument that is passed inside of our function, so we would probably want to change this to something like cap_word.

# compare the word_letter_count and bank_letter_count to see if word can be made
for letter, count in word_letter_count.items():
# check if not in bank_letter_count
if letter not in bank_letter_count or count > bank_letter_count[letter]:

Choose a reason for hiding this comment

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

Nice use of the not in expression here! I love it!

if len(word) >= 7 and len(word) <= 10:
# add 8 to score var
score += 8
return score

Choose a reason for hiding this comment

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

Excellent concise and readable function! ⭐️

if (len(word) == 10 and len(winning_word) < 10) or len(word) > len(winning_word):
winning_word = word
# create code block for if the two highest words are less than 10 choose the shortest word

Choose a reason for hiding this comment

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

So it seems like you may of had trouble with the tie-breaking logic, it is a bit tricky! So the first thing you probably want to change its data structure you gave winning_word, I would probaly change it into a list so we could append multiple potential winning words to it. After that we can implement something like this:

def get_highest_word_score(word_list):
    highest_score = 0
    winning_words = []

    for word in word_list:
       score = score_word(word)
       
       if score > highest_score:
          highest_score = score
          winning_words = [word] #replacing winning)words when the score of the current word is higher than the high score
       elif score == highest_score:
          winning_words.append(word) #we append to winning_words when the score of said word is equal to the high score
    
    if len(winning_words) > 1: #only applying tie-breaking logic when we have more than 1 potential winner
       for word in winning_words: 
          if len(word) == 10: # returns the 1st 10 letter word in list 
             return word, highest_score # all winning words we will have the same score since they are tied.
       
       min_word = min(winning_words, key=len) #if we make it pass the return statement we will find the shortest word based on length
       winning_words = [min_word]

    return winning_words[0], highest_score

winning_word = word
# create code block for if the two highest words are less than 10 choose the shortest word
return (winning_word, highest_score)

Choose a reason for hiding this comment

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

Nice job Raina and congrats on finishing your first official Ada project! Please feel free to reach out if you have any questions about the comments I left! ⭐️

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.

2 participants