diff --git a/2024/ruby/day_07.rb b/2024/ruby/day_07.rb index c92f2a3..6a2d723 100644 --- a/2024/ruby/day_07.rb +++ b/2024/ruby/day_07.rb @@ -6,9 +6,11 @@ input = DATA.readlines pp input.filter_map {|val, vars| vals = vars.inject {|n,x| - %i[ + * ].flat_map {|op| - Array(n).map { _1.send(op, x) } - } + Array(n).flat_map {[ + _1 + x, + _1 * x, + "#{_1}#{x}".to_i, + ]} } vals.include?(val) && val }.sum