day 22 part 2

This commit is contained in:
Felix Van der Jeugt 2021-12-22 17:44:52 +01:00
parent 6ef26926ad
commit 9c96d30ea6
No known key found for this signature in database
GPG Key ID: 58B209295023754D
1 changed files with 23 additions and 25 deletions

View File

@ -57,39 +57,37 @@ local function cut3d(a, b)
}
for _, combo in pairs(nobscombos) do
local xs, ys, zs = unpack(combo)
for _, x in pairs(xs) do
for _, y in pairs(ys) do
for _, z in pairs(zs) do
for _, x in pairs(xs) do if x.s < x.e then
for _, y in pairs(ys) do if y.s < y.e then
for _, z in pairs(zs) do if z.s < z.e then
table.insert(aparts, { b = a.b, x=x, y=y, z=z })
end
end
end
end end
end end
end end
end
return aparts
end
local fixed = { ranges[1] }
table.remove(ranges, 1)
for _, range in pairs(ranges) do
local newfixed = {}
--printtable(range)
if range.b then
table.insert(newfixed, range)
end
for _, f in pairs(fixed) do
for _, fpart in pairs(cut3d(f, range)) do
--io.write(" ")
--printtable(fpart)
table.insert(newfixed, fpart)
local count = 0
for i = 1, #ranges do
if ranges[i].b then
print(i, os.clock())
local fixed = { ranges[i] }
for j = i + 1, #ranges do
local newfixed = {}
for _, f in pairs(fixed) do
for _, fpart in pairs(cut3d(f, ranges[j])) do
table.insert(newfixed, fpart)
end
end
fixed = newfixed
end
for _, r in pairs(fixed) do
-- printtable(r)
count = count + (r.x.e - r.x.s)*(r.y.e - r.y.s)*(r.z.e - r.z.s)
end
end
fixed = newfixed
end
local count = 0
for _, r in pairs(fixed) do
-- printtable(r)
count = count + (r.x.e - r.x.s)*(r.y.e - r.y.s)*(r.z.e - r.z.s)
end
io.write(string.format("%d\n", count))