From cd7ed1621b3b4b1c368c4cc9e21731038464a2ab Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sat, 7 Dec 2024 12:59:23 -0800 Subject: [PATCH] [2024][ruby][7.2] --- 2024/ruby/day_07.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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