Something went wrong. Try again.
Code for the Advent of Code event
aoc advent-of-code
Something went wrong. Try again.
713 B · 30 lines
Lua
at main
12345678910111213141516171819202122232425262728293031local grid = require("grid")
grid.init(false)
local ops = { ["on"] = function() return true end, ["off"] = function() return false end, ["toggle"] = function(cell) return not cell end}
local function count() return grid.accum(0, function(accum, cell) return accum + (cell and 1 or 0) end)end
local input = io.open("input.txt", "r")
for line in input:lines("l") do local op, startx, starty, endx, endy = line:match("(%w+) (%d+),(%d+) through (%d+),(%d+)")
startx = tonumber(startx) starty = tonumber(starty) endx = tonumber(endx) endy = tonumber(endy)
grid.apply(ops[op], startx, endx, starty, endy)end
input:close()
print(("%d lights are lit"):format(count()))