day 22 part 1

This commit is contained in:
Felix Van der Jeugt 2021-12-22 12:47:58 +01:00
parent 7f9f94aa51
commit 9e4c9c4d03
No known key found for this signature in database
GPG Key ID: 58B209295023754D

31
day22/part1.lua Executable file
View File

@ -0,0 +1,31 @@
#!/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)