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
Sophie/Emily's Adagram Submission #22
Open
emirry
wants to merge
17
commits into
Ada-C14:master
Choose a base branch
from
steve-messing: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
17 commits
Select commit
Hold shift + click to select a range
e21a635
create draw_letters method
steve-messing f532813
remove comments
steve-messing 3c149f6
"draw_letters samples and deletes from rand index"
steve-messing 4e6387b
created a hash method to count and compare letter frequencies in word…
steve-messing e332154
wave 3
steve-messing 0838de8
most recent version with working methods for waves 1-3
steve-messing b14acdb
highest-score-draft
emirry 4a85a5a
highest score failures
emirry 0237e7e
highscore 2 passes
emirry da4da48
ajga
emirry cce19a8
Merge branch 'master' into master
emirry 8f78ecd
Merge pull request #1 from emirry/master
emirry f4e7220
sophie tried to make a highest_score_from method
steve-messing d6c51e1
done
emirry 416c42f
merge conflict
steve-messing d3489c2
cleaned up line spacing
steve-messing 625c3ab
added wave 5 and wrote tests
steve-messing 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,139 @@ | ||
require 'csv' | ||
|
||
def draw_letters | ||
distribution = { | ||
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, | ||
} | ||
|
||
distribution_array = [] | ||
distribution.each do |letter, number| | ||
number.times do | ||
distribution_array << letter.to_s | ||
end | ||
end | ||
|
||
drawn_letters = [] | ||
10.times do | ||
index = rand(0...distribution_array.length) | ||
drawn_letters << distribution_array[index] | ||
distribution_array.delete_at(index) | ||
end | ||
return drawn_letters | ||
end | ||
|
||
def uses_available_letters?(input, letters_in_hand) | ||
input_hash = Hash.new(0) | ||
input.upcase! | ||
input = input.split('') | ||
input.each do |letter| | ||
input_hash[letter] += 1 | ||
end | ||
input = input_hash | ||
|
||
letter_hash = Hash.new(0) | ||
letters_in_hand.each do |letter| | ||
letter_hash[letter] += 1 | ||
end | ||
letters_in_hand = letter_hash | ||
|
||
input.each do |letter, count| | ||
if letters_in_hand[letter] < count | ||
return false | ||
end | ||
end | ||
|
||
return true | ||
end | ||
|
||
def score_word(word) | ||
if word.length >= 7 | ||
score = 8 | ||
else | ||
score = 0 | ||
end | ||
|
||
hash = Hash.new(0) | ||
word.upcase! | ||
word = word.split('') | ||
word.each do |letter| | ||
hash[letter] += 1 | ||
end | ||
word = hash | ||
|
||
values = { | ||
"A" => 1, "E" => 1, "I" => 1, "O" => 1, "U" => 1, "L" => 1, "N" => 1, "R" => 1, "S" => 1, "T" => 1, | ||
"D" => 2, "G" => 2, | ||
"B" => 3, "C" => 3, "M" => 3, "P" => 3, | ||
"F" => 4, "H" => 4, "V" => 4, "W" => 4, "Y" => 4, | ||
"K" => 5, | ||
"J" => 8, "X" => 8, | ||
"Q" => 10, "Z" => 10 | ||
} | ||
|
||
values.each do |letter, value| | ||
score += (word[letter] * values[letter]) | ||
end | ||
|
||
return score | ||
end | ||
|
||
def highest_score_from(words) | ||
|
||
best_word = Hash.new | ||
|
||
best_score = 0 | ||
winning_word = "" | ||
|
||
words.each do |word| | ||
score = score_word(word) | ||
if score > best_score | ||
winning_word = word | ||
best_score = score | ||
elsif word.length == 10 && score == best_score && winning_word.length < 10 | ||
winning_word = word | ||
best_score = score | ||
elsif score == best_score && word.length < winning_word.length && winning_word.length != 10 | ||
winning_word = word | ||
best_score = score | ||
end | ||
end | ||
|
||
best_word[:word] = winning_word | ||
best_word[:score] = best_score | ||
|
||
return best_word | ||
end | ||
|
||
def is_in_english_dict?(input) | ||
english_dict = CSV.read("assets/dictionary-english.csv").flatten | ||
if english_dict.include?(input) | ||
return true | ||
else | ||
return false | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -178,4 +178,38 @@ | |
expect(best_word[:score]).must_equal 18 | ||
end | ||
end | ||
|
||
describe 'is_in_english_dict?' do | ||
it 'returns true for words less than or equal to 10 letters in the english dictionary' do | ||
|
||
input = "chickens" | ||
result = is_in_english_dict?(input) | ||
expect(result).must_equal true | ||
|
||
input = "dog" | ||
result = is_in_english_dict?(input) | ||
expect(result).must_equal true | ||
|
||
end | ||
|
||
it 'returns false for words not in the english dictionary' do | ||
|
||
input = "sdfjs" | ||
result = is_in_english_dict?(input) | ||
expect(result).must_equal false | ||
|
||
input = "appple" | ||
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. you never eaten an appple before? \j |
||
result = is_in_english_dict?(input) | ||
expect(result).must_equal false | ||
|
||
end | ||
|
||
it 'returns false for valid words in the dictionary over 10 letters' do | ||
|
||
input = "responsibility" | ||
result = is_in_english_dict?(input) | ||
expect(result).must_equal false | ||
|
||
end | ||
end | ||
end |
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.
Interesting that y'all chose two different hash styles in this assignment. IMO this kind of inconsistency can create readability problems, so keep an eye out for that!