diff --git a/2024/ruby/day_03.rb b/2024/ruby/day_03.rb index d307b67..76c9227 100644 --- a/2024/ruby/day_03.rb +++ b/2024/ruby/day_03.rb @@ -1,9 +1,22 @@ -input = DATA.read - .gsub(/don't\(\)(?~do\(\))do\(\)/, "") # part two - .scan(/mul\((\d+),(\d+)\)/) - .map { _1.map(&:to_i) } +# input = DATA.read +# .gsub(/don't\(\)(?~do\(\))do\(\)/, "") # part two +# .scan(/mul\((\d+),(\d+)\)/) +# .map { _1.map(&:to_i) } +# +# pp input.sum { _1 * _2 } -pp input.sum { _1 * _2 } +# because I felt like using a flip-flop... +input = DATA.read.scan(/(do|don't)\(\)|mul\((\d+),(\d+)\)/) +input.unshift(["do"]) + +sum = 0 +input.each do |dodont, *mul| + next unless (dodont == "do")..(dodont == "don't") + next unless dodont.nil? + a, b = mul.map(&:to_i) + sum += a * b +end +pp sum __END__ xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))