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

Moyo_Ruby_adagrams #114

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

Moyo_Ruby_adagrams #114

wants to merge 8 commits into from

Conversation

MoyoMoz
Copy link

@MoyoMoz MoyoMoz commented Mar 24, 2023

OMG this was so hard

Copy link

@nancy-harris nancy-harris left a comment

Choose a reason for hiding this comment

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

Excellent job! I left some comments for you below on places where the code could be cleaner/simpler. Consider adding commits more often!

import random

# Function to draw 10 random letters from the letter pool

def draw_letters():

Choose a reason for hiding this comment

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

Excellent job!

def draw_letters():
pass
LETTER_POOL = {

Choose a reason for hiding this comment

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

Since this dictionary is never changed, it would be good to have it declared outside of the function so that it doesn't have to be recreated each time the function is called.

# Create a list of letters with the frequency as specified in the pool
letter_list = []
for letter, count in LETTER_POOL.items():
letter_list.extend([letter] * count)

Choose a reason for hiding this comment

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

Nice!


return hand

# Function to check if the given word can be formed using the available letters
def uses_available_letters(word, letter_bank):

Choose a reason for hiding this comment

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

Excellent, very concise code!

return False

# If all letters are in the letter bank copy, the word is valid
return True

def score_word(word):

Choose a reason for hiding this comment

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

Excellent!


def score_word(word):
pass
word = word.upper()
letter_scores = {

Choose a reason for hiding this comment

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

Similar to the letter pool above, this dictionary can be declared outside of the function.

Comment on lines +70 to +85
# If the scores are equal, apply tie-breaking rules:
score == highest_word[1] and (
# If the current word has 10 letters and the highest_word doesn't, choose the current word
(len(word) == 10 and len(highest_word[0]) != 10) or
# If neither word has 10 letters, choose the word with fewer letters
(len(highest_word[0]) != 10 and len(word) < len(highest_word[0]))
)
):
# Update the highest_word with the current word and its score
highest_word = (word, score)
# If the scores are equal and the word lengths are also equal, use the order in the supplied list
elif score == highest_word[1] and len(word) == len(highest_word[0]):
# Check the index of the current word and highest_word in the original list
# If the index of the current word is lower, update highest_word with the current word and its score
highest_word = (word_list.index(word) < word_list.index(highest_word[0])) and (word, score) or highest_word

Choose a reason for hiding this comment

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

These statements are a bit hard to read. For the sake of keeping the code readable, it might be worth it to have if and elif statements here to lay out the logic rather than trying to get everything together with ands and ors.

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