forked from AdaGold/adagrams
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Leaves_Ga-Young&Raisah #2
Open
gyjin
wants to merge
9
commits into
Ada-C12:master
Choose a base branch
from
gyjin: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
9 commits
Select commit
Hold shift + click to select a range
fe2b17c
Completed wave-1 in adagrams.rb
c2f0ad7
Attempt at wave-2 in adagrams.rb
81aed00
Completed wave-2
1ca9f10
Completed wave-3 for adagrams.rb
fb5d59f
Attempt at wave-4
d03b705
Completed wave-4 in adagrams.rb
6012e51
Recommit completed wave-4
a9aa956
Refactored adagrams.rb
87f81c7
Completed wave-5 in adagrams.rb
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,171 @@ | ||
# Ga-Young Jin, Raisah Vesteinsdottir Cohort 12 | ||
# Monday, August 12th, 2019 | ||
# Week 2, Adagram Project | ||
|
||
require 'csv' | ||
SIZE_OF_HAND = 10 | ||
|
||
# wave-1 | ||
def draw_letters | ||
letter_dist = { # given distribution of letters | ||
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 | ||
} | ||
|
||
# putting all available letters into one array | ||
all_letters = [] | ||
|
||
letter_dist.each do |letter, quantity| | ||
quantity.times do | ||
all_letters << letter.to_s | ||
end | ||
end | ||
|
||
# create randomized hand | ||
shuffled_all_letters = all_letters.shuffle | ||
hand = [] | ||
|
||
SIZE_OF_HAND.times do |i| | ||
hand << shuffled_all_letters[i] | ||
end | ||
return hand | ||
end | ||
|
||
# wave-2 | ||
def uses_available_letters?(input, letters_in_hand) | ||
input_as_array = input.upcase.split("") | ||
hand_in_hash = {} | ||
|
||
# determines if string is longer than size of hand | ||
return false if input_as_array.length > SIZE_OF_HAND | ||
|
||
# converts letters_in_hand array to hash | ||
letters_in_hand.each do |char| | ||
if hand_in_hash.has_key?(char) == true | ||
hand_in_hash[char] += 1 | ||
else | ||
hand_in_hash[char] = 1 | ||
end | ||
end | ||
|
||
# determines if letters in string are present in hand | ||
input_as_array.each do |char| | ||
if hand_in_hash.has_key?(char) == true | ||
hand_in_hash[char] -= 1 | ||
else | ||
return false | ||
end | ||
end | ||
|
||
return hand_in_hash.values.min < 0 ? false : true | ||
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. Nice! Clever! I dig it! |
||
end | ||
|
||
# wave-3 | ||
def score_word(word) | ||
word_as_array = word.upcase.split("") | ||
|
||
score_chart = { | ||
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 | ||
} | ||
|
||
# calculate score based on letters in word | ||
score = 0 | ||
word_as_array.each do |char| | ||
score += score_chart[char.to_sym] | ||
end | ||
|
||
score += 8 if word.length > 6 | ||
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. Succinct! |
||
|
||
return score | ||
end | ||
|
||
# wave-4 | ||
def highest_score_from(words) | ||
winning_word_score = {word: "", score: 0} | ||
highest_score = {word: [], score: 0} | ||
|
||
# save highest score and word(s) into hash | ||
words.each do |word| | ||
score_of_word = score_word(word) | ||
if highest_score[:score] < score_of_word | ||
highest_score[:score] = score_of_word | ||
highest_score[:word] = [word] | ||
elsif highest_score[:score] == score_of_word | ||
highest_score[:word] << word | ||
end | ||
end | ||
|
||
winning_word_score[:score] = highest_score[:score] | ||
|
||
# determines winning word in case of score tie | ||
if highest_score[:word].length == 1 | ||
winning_word_score[:word] = highest_score[:word][0] | ||
elsif highest_score[:word].length > 1 | ||
if highest_score[:word].max_by{|x| x.length}.length == 10 | ||
winning_word_score[:word] = highest_score[:word].max_by{|x| x.length} | ||
else | ||
winning_word_score[:word] = highest_score[:word].min_by{|x| x.length} | ||
end | ||
end | ||
|
||
return winning_word_score | ||
end | ||
|
||
# wave-5 | ||
# checking to see if word input is a real word | ||
def is_in_english_dict?(input) | ||
CSV.open("assets/dictionary-english.csv").each do |word| | ||
return true if input == word[0] | ||
end | ||
|
||
return false | ||
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.
Solid process here!