wip
Alpha Chen 9 years ago
parent 4ec4623403
commit 8e51f67b61

@ -1,8 +1,8 @@
lights = Hash.new {|h,k| h[k] = false } lights = Hash.new {|h,k| h[k] = 0 }
instructions = { "turn on" => ->(_) { true }, instructions = { "turn on" => ->(intensity) { intensity + 1 },
"turn off" => ->(_) { false }, "turn off" => ->(intensity) { intensity.zero? ? 0 : intensity - 1 },
"toggle" => ->(light) { !light } } "toggle" => ->(intensity) { intensity + 2 } }
regex = /(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/ regex = /(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/
DATA.read.scan(regex).each do |instruction, x1,y1, x2,y2| DATA.read.scan(regex).each do |instruction, x1,y1, x2,y2|
@ -17,7 +17,7 @@ DATA.read.scan(regex).each do |instruction, x1,y1, x2,y2|
end end
end end
puts lights.values.count {|light| light } puts lights.values.inject(&:+)
__END__ __END__
turn on 887,9 through 959,629 turn on 887,9 through 959,629

Loading…
Cancel
Save