You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
advent-of-code/2024/ruby/day_03.rb

23 lines
540 B

# input = DATA.read
# .gsub(/don't\(\)(?~do\(\))do\(\)/, "") # part two
# .scan(/mul\((\d+),(\d+)\)/)
# .map { _1.map(&:to_i) }
#
# 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))