parent
54c626efc3
commit
7591a5dc19
@ -1,9 +1,22 @@
|
|||||||
input = DATA.read
|
# input = DATA.read
|
||||||
.gsub(/don't\(\)(?~do\(\))do\(\)/, "") # part two
|
# .gsub(/don't\(\)(?~do\(\))do\(\)/, "") # part two
|
||||||
.scan(/mul\((\d+),(\d+)\)/)
|
# .scan(/mul\((\d+),(\d+)\)/)
|
||||||
.map { _1.map(&:to_i) }
|
# .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__
|
__END__
|
||||||
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))
|
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))
|
||||||
|
Loading…
Reference in new issue