From 8e51f67b618ae6bc9ccbc2e48276d6070ea49733 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 9 Dec 2015 11:45:01 -0800 Subject: [PATCH] Day 6.2 --- day_06.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/day_06.rb b/day_06.rb index 5a99de2..c51aa3b 100644 --- a/day_06.rb +++ b/day_06.rb @@ -1,8 +1,8 @@ -lights = Hash.new {|h,k| h[k] = false } +lights = Hash.new {|h,k| h[k] = 0 } -instructions = { "turn on" => ->(_) { true }, - "turn off" => ->(_) { false }, - "toggle" => ->(light) { !light } } +instructions = { "turn on" => ->(intensity) { intensity + 1 }, + "turn off" => ->(intensity) { intensity.zero? ? 0 : intensity - 1 }, + "toggle" => ->(intensity) { intensity + 2 } } regex = /(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)/ 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 -puts lights.values.count {|light| light } +puts lights.values.inject(&:+) __END__ turn on 887,9 through 959,629