-
Notifications
You must be signed in to change notification settings - Fork 0
[Scrabble task] Solution for scrabble puzzle #8
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
base: master
Are you sure you want to change the base?
Conversation
Training/Medium/scrabble.rb
Outdated
| letters_weight[2] = %w(d g) | ||
| letters_weight[3] = %w(b c m p) | ||
| letters_weight[4] = %w(f h v w y) | ||
| letters_weight[5] = ['k'] |
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.
It's okay to %w(k) for consistency.
Training/Medium/scrabble.rb
Outdated
|
|
||
| def initialize | ||
| @n = gets.to_i | ||
| @dictionary = @n.times.each_with_object([]) { |_, result| result << gets.chomp } |
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.
Define a local n variable here. You don't need instance one.
@dictionary = Array.new(n) { gets.chomp }
Training/Medium/scrabble.rb
Outdated
| end | ||
|
|
||
| def init_letters_weight | ||
| letters_weight = {} |
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.
You can define a hash to return at once:
def init_letters_weight
{
1 => %w(e a i o n r t l s u),
2 => %w(d g),
...
}
end| end | ||
|
|
||
| def matching?(word) | ||
| word.each_char do |char| |
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.
One way to refactor is to use an any? block for this method.
Training/Medium/scrabble.rb
Outdated
| end | ||
|
|
||
| obj = Scrabble.new | ||
| obj.start |
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.
You can say:
puts obj.find_all_wordsbddf776 to
638fceb
Compare
No description provided.