day 22 part 1
This commit is contained in:
parent
7f9f94aa51
commit
9e4c9c4d03
31
day22/part1.lua
Executable file
31
day22/part1.lua
Executable 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)
|
Loading…
Reference in New Issue
Block a user