forked from AdaGold/adagrams
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Jessica and Kayla Pull Request #6
Open
jwinchan
wants to merge
14
commits into
Ada-C14:master
Choose a base branch
from
jwinchan:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1b0b450
created an array with letters time frequency times
Kaylaj89 1132a84
added .sample to the array
jwinchan c343173
Added wave 1 to adagrams.rb
Kaylaj89 0f15091
started wave 2 in adagrams.rb
jwinchan bd95528
finished wave 2
Kaylaj89 bcf5f3d
style and formatting changes
jwinchan c0b3e25
some more style changes
jwinchan 1e7c4bc
We added word score method
Kaylaj89 b78a7c3
started highest_score method
jwinchan ad2a31d
started tie breaker for highest_score
jwinchan c51592a
Added tiebreaker info for 10 letter words
Kaylaj89 798beef
added u and .upcase in wave 2
jwinchan 40442bc
changed .delete to .delete_at
jwinchan 0c02b7e
added comments before submission
Kaylaj89 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
def draw_letters | ||
letters_hash = { 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 } | ||
letters_array = [] | ||
|
||
# create an array with all the letters matching their frequency | ||
letters_hash.each_pair do |letter, frequency| | ||
frequency.times do | ||
letters_array.push(letter.to_s) | ||
end | ||
end | ||
return letters_array.sample(10) | ||
end | ||
|
||
#Make a copy of letters_in_hand and delete as we cycle through input_array letters | ||
def uses_available_letters?(input, letters_in_hand) | ||
input_array = input.upcase.chars | ||
letters_copy = letters_in_hand.dup | ||
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. Good use of "defensive" copying. |
||
if input_array.length <= letters_in_hand.length | ||
input_array.each do |letter| | ||
if letters_copy.include?(letter) | ||
letters_copy.delete_at(letters_copy.index(letter)) | ||
else | ||
return false | ||
end | ||
end | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def score_word(word) | ||
word_array = word.upcase.chars | ||
score = 0 | ||
|
||
if word_array.length > 6 | ||
score += 8 | ||
end | ||
|
||
word_array.each do |letter| | ||
case letter | ||
when "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" | ||
score += 1 | ||
when "D", "G" | ||
score += 2 | ||
when "B", "C", "M", "P" | ||
score += 3 | ||
when "F", "H", "V", "W", "Y" | ||
score += 4 | ||
when "K" | ||
score += 5 | ||
when "J", "X" | ||
score += 8 | ||
when "Q", "Z" | ||
score += 10 | ||
end | ||
end | ||
return score | ||
end | ||
|
||
# create 3 different scenarios for highest_score | ||
# scenario 1: single high scoring word | ||
def highest_score_from(words) | ||
best_words = [] | ||
highest_score = 0 | ||
winner = {} | ||
words.each do |word| | ||
if score_word(word) > highest_score | ||
best_words.clear | ||
best_words << word | ||
highest_score = score_word(word) | ||
elsif score_word(word) == highest_score | ||
best_words << word | ||
end | ||
end | ||
|
||
# scenario 2: first ten letter word wins in tie-break | ||
# scenario 3: first shortest word wins in tie-break | ||
if best_words.length > 1 | ||
tie_breaker = [] | ||
word_length = 10 | ||
best_words.each do |word| | ||
if word.length == 10 | ||
tie_breaker.clear | ||
tie_breaker << word | ||
break | ||
elsif word.length < word_length | ||
tie_breaker.clear | ||
tie_breaker << word | ||
word_length = word.length | ||
end | ||
end | ||
winning_word_array = tie_breaker | ||
else | ||
winning_word_array = best_words | ||
end | ||
|
||
#Assigning hash values | ||
winner[:word] = winning_word_array[0] | ||
winner[:score] = highest_score | ||
return winner | ||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Good use of
sample
!