adventofcode-2021/day22/part1.lua
Felix Van der Jeugt 9e4c9c4d03
day 22 part 1
2021-12-22 12:47:58 +01:00

32 lines
685 B
Lua
Executable File

#!/usr/bin/env luajit
require("utils")
local ranges = {}
for line in io.lines(arg[3]) do
local b, x0, x1, y0, y1, z0, z1 = line:match("(.*) x=(.*)%.%.(.*),y=(.*)%.%.(.*),z=(.*)%.%.(.*)")
if b == "on" then b = true else b = false end
table.insert(ranges, {
b=b,
x0=tonumber(x0),
x1=tonumber(x1),
y0=tonumber(y0),
y1=tonumber(y1),
z0=tonumber(z0),
z1=tonumber(z1)
})
end
local count = 0
for x = -50, 50 do for y = -50, 50 do for z = -50, 50 do
local on = false
for _, r in pairs(ranges) do
if r.x0 <= x and x <= r.x1 and r.y0 <= y and y <= r.y1 and r.z0 <= z and z <= r.z1 then
on = r.b
end
end
if on then
count = count + 1
end
end end end
print(count)