Class: WordleDecoder::WordSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/wordle_decoder/word_search.rb

Constant Summary collapse

COMMONALITY_OPTIONS =
i[most less least].freeze

Class Method Summary collapse

Class Method Details

.char_at_index(char, index, commonality) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/wordle_decoder/word_search.rb', line 10

def char_at_index(char, index, commonality)
  case commonality
  when :most
    most_common_letter_to_words_arrays[index][char]
  when :less
    less_common_letter_to_words_arrays[index][char]
  when :least
    least_common_letter_to_words_arrays[index][char]
  end || []
end

.chars_at_index(chars, index, commonality) ⇒ Object



21
22
23
# File 'lib/wordle_decoder/word_search.rb', line 21

def chars_at_index(chars, index, commonality)
  chars.uniq.flat_map { |char| char_at_index(char, index, commonality) }
end

.frequency_score(word) ⇒ Object



25
26
27
# File 'lib/wordle_decoder/word_search.rb', line 25

def frequency_score(word)
  words_to_frequency_score_hash[word]
end

.most_frequent_words_without_chars(without_chars, limit) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/wordle_decoder/word_search.rb', line 33

def most_frequent_words_without_chars(without_chars, limit)
  regex = /#{without_chars.join("|")}/
  words = []
  words_to_frequency_score_hash.each_key.reverse_each do |str|
    words << str unless str.match?(regex)

    return(words) if words.count == limit
  end
end

.words_to_frequency_score_hashObject



29
30
31
# File 'lib/wordle_decoder/word_search.rb', line 29

def words_to_frequency_score_hash
  @words_to_frequency_score_hash ||= load_words_to_frequency_score_hash
end