day 22 part 2
This commit is contained in:
parent
6ef26926ad
commit
9c96d30ea6
@ -57,39 +57,37 @@ local function cut3d(a, b)
|
|||||||
}
|
}
|
||||||
for _, combo in pairs(nobscombos) do
|
for _, combo in pairs(nobscombos) do
|
||||||
local xs, ys, zs = unpack(combo)
|
local xs, ys, zs = unpack(combo)
|
||||||
for _, x in pairs(xs) do
|
for _, x in pairs(xs) do if x.s < x.e then
|
||||||
for _, y in pairs(ys) do
|
for _, y in pairs(ys) do if y.s < y.e then
|
||||||
for _, z in pairs(zs) do
|
for _, z in pairs(zs) do if z.s < z.e then
|
||||||
table.insert(aparts, { b = a.b, x=x, y=y, z=z })
|
table.insert(aparts, { b = a.b, x=x, y=y, z=z })
|
||||||
end
|
end end
|
||||||
end
|
end end
|
||||||
end
|
end end
|
||||||
end
|
end
|
||||||
|
|
||||||
return aparts
|
return aparts
|
||||||
end
|
end
|
||||||
|
|
||||||
local fixed = { ranges[1] }
|
local count = 0
|
||||||
table.remove(ranges, 1)
|
for i = 1, #ranges do
|
||||||
for _, range in pairs(ranges) do
|
if ranges[i].b then
|
||||||
local newfixed = {}
|
print(i, os.clock())
|
||||||
--printtable(range)
|
local fixed = { ranges[i] }
|
||||||
if range.b then
|
for j = i + 1, #ranges do
|
||||||
table.insert(newfixed, range)
|
local newfixed = {}
|
||||||
end
|
for _, f in pairs(fixed) do
|
||||||
for _, f in pairs(fixed) do
|
for _, fpart in pairs(cut3d(f, ranges[j])) do
|
||||||
for _, fpart in pairs(cut3d(f, range)) do
|
table.insert(newfixed, fpart)
|
||||||
--io.write(" ")
|
end
|
||||||
--printtable(fpart)
|
end
|
||||||
table.insert(newfixed, fpart)
|
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
|
||||||
end
|
end
|
||||||
fixed = newfixed
|
|
||||||
end
|
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))
|
io.write(string.format("%d\n", count))
|
||||||
|
Loading…
Reference in New Issue
Block a user