Class: Lm::String122ResultSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/lm/string_122_result_selector.rb

Instance Method Summary collapse

Constructor Details

#initialize(pm, sum) ⇒ String122ResultSelector

Returns a new instance of String122ResultSelector.



5
6
7
8
# File 'lib/lm/string_122_result_selector.rb', line 5

def initialize(pm, sum)
  @pm = pm
  @sum = sum
end

Instance Method Details

#chartObject



10
11
12
13
14
15
16
17
# File 'lib/lm/string_122_result_selector.rb', line 10

def chart
  @chart ||= @pm.soplist.map do |k, v|
    {
      columns: k,
      product: v
    }
  end
end

#shortestObject



32
33
34
35
# File 'lib/lm/string_122_result_selector.rb', line 32

def shortest
  idx = sum_strings.min_by { |x| x[:str].length }[:idx]
  SumOfProducts.new(sum_list[idx])
end

#sum_listObject



19
20
21
22
23
24
25
26
# File 'lib/lm/string_122_result_selector.rb', line 19

def sum_list
  @sum.str.split("+").map do |term|
    term.split("").map do |str122|
      idx = str122.ord - 48
      chart[idx][:product]
    end
  end
end

#sum_stringsObject



28
29
30
# File 'lib/lm/string_122_result_selector.rb', line 28

def sum_strings
  sum_list.each_with_index.map { |x, i| { str: x.join("+"), idx: i } }
end