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
Adagrams Completed Kalki & Alice D. #20
Open
codeandmorecode
wants to merge
5
commits into
Ada-C14:master
Choose a base branch
from
codeandmorecode: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
5 commits
Select commit
Hold shift + click to select a range
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,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Settings><!--This file was automatically generated by Ruby plugin. | ||
You are allowed to: | ||
1. Remove rake task | ||
2. Add existing rake tasks | ||
To add existing rake tasks automatically delete this file and reload the project. | ||
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Run tests" fullCmd="test" taksId="test" /><RakeTask description="" fullCmd="default" taksId="default" /></RakeGroup></Settings> |
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ GEM | |
|
||
PLATFORMS | ||
ruby | ||
x64-mingw32 | ||
|
||
DEPENDENCIES | ||
minitest | ||
|
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,102 @@ | ||
# WAVE 1 - The method draw_letters extracts a sample of 10 letters from the letter_pool array | ||
def draw_letters | ||
letter_pool = %w( | ||
A A A A A A A A A | ||
B B | ||
C C | ||
D D D D | ||
E E E E E E E E E E E E | ||
F F | ||
G G G | ||
H H | ||
I I I I I I I I I | ||
J | ||
K | ||
L L L L | ||
M M | ||
N N N N N N | ||
O O O O O O O O | ||
P P | ||
Q | ||
R R R R R R | ||
S S S S | ||
T T T T T T | ||
U U U U | ||
V V | ||
W W | ||
X | ||
Y | ||
Z | ||
) | ||
return letter_pool.sample(10) | ||
|
||
end | ||
|
||
# WAVE 2 - The method uses_available_letters? checks input against letters_in_hand and returns true if input is in letters_in_hand, false otherwise | ||
def uses_available_letters?(input, letters_in_hand) | ||
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. 👍 |
||
|
||
new_letters_in_hand = letters_in_hand.dup | ||
|
||
input.upcase.chars.each do |character| | ||
if new_letters_in_hand.include?(character) | ||
position = new_letters_in_hand.index(character) | ||
new_letters_in_hand.delete_at(position) | ||
else | ||
return false | ||
end | ||
end | ||
return true | ||
end | ||
|
||
# WAVE 3 - The method score_word will tally points for words submitted by user | ||
def score_word(word) | ||
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. 👍 |
||
|
||
score = 0 | ||
|
||
word_char_array = word.upcase.chars | ||
|
||
word_char_array.each do |character| | ||
case character | ||
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 | ||
|
||
if word_char_array.length >= 7 | ||
score += 8 | ||
end | ||
|
||
return score | ||
end | ||
|
||
|
||
# WAVE 4 - The method highest_score_from returns the winning word and winning score; checks ties | ||
def highest_score_from(words) | ||
Comment on lines
+85
to
+86
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. 👍 |
||
|
||
winner = {word: nil, score: 0} | ||
words.each do |word| | ||
|
||
if score_word(word) > winner[:score] | ||
winner[:word] = word | ||
winner[:score] = score_word(word) | ||
elsif score_word(word) == winner[:score] | ||
if ((winner[:word]).length != 10) && (word.length < (winner[:word]).length || word.length == 10) | ||
winner[:word] = word | ||
winner[:score] = score_word(word) | ||
end | ||
end | ||
end | ||
return winner | ||
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.
👍 Clever and simple way to set up the distribution of letters.