Formatting
parent
daa7f3eeb5
commit
4386d976f1
|
@ -5,9 +5,9 @@ input = File.readlines('./input').map(&:strip)
|
|||
|
||||
lights = Array.new(1000) { Array.new(1000, false) }
|
||||
|
||||
instructions = Hash.new
|
||||
instructions = {}
|
||||
|
||||
instructions = input.map.with_index do |line, i|
|
||||
instructions = input.map.with_index do |line, _i|
|
||||
line.slice!('turn')
|
||||
line = line.split(' ')
|
||||
{ Command: line[0], Start: line[1].split(',').map!(&:to_i), End: line[3].split(',').map!(&:to_i) }
|
||||
|
@ -24,7 +24,8 @@ instructions.each do | instruction |
|
|||
when 'off'
|
||||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] = false
|
||||
when 'toggle'
|
||||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] = !(lights[instruction[:Start][0] + x][ instruction[:Start][1] + y])
|
||||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] =
|
||||
!(lights[instruction[:Start][0] + x][ instruction[:Start][1] + y])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -44,7 +45,10 @@ instructions.each do | instruction |
|
|||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] += 1
|
||||
when 'off'
|
||||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] -= 1
|
||||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] = 0 if lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] < 0
|
||||
if lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] < 0
|
||||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] =
|
||||
0
|
||||
end
|
||||
when 'toggle'
|
||||
lights[instruction[:Start][0] + x][ instruction[:Start][1] + y] += 2
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue