Skip to content

[Scrabble task] Solution for scrabble puzzle#8

Open
Slavunderkind wants to merge 3 commits into
masterfrom
scrabble_solution
Open

[Scrabble task] Solution for scrabble puzzle#8
Slavunderkind wants to merge 3 commits into
masterfrom
scrabble_solution

Conversation

@Slavunderkind

Copy link
Copy Markdown
Owner

No description provided.

Comment thread 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']

Copy link
Copy Markdown

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.

Comment thread Training/Medium/scrabble.rb Outdated

def initialize
@n = gets.to_i
@dictionary = @n.times.each_with_object([]) { |_, result| result << gets.chomp }

Copy link
Copy Markdown

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 }

Comment thread Training/Medium/scrabble.rb Outdated
end

def init_letters_weight
letters_weight = {}

Copy link
Copy Markdown

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|

Copy link
Copy Markdown

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.

Comment thread Training/Medium/scrabble.rb Outdated
end

obj = Scrabble.new
obj.start

Copy link
Copy Markdown

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_words

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant