This commit is contained in:
basicbonobo 2023-12-25 19:37:01 +01:00
parent 9c41bbdb37
commit 44d78ccdc6
3 changed files with 1296 additions and 0 deletions

1249
input22 Normal file

File diff suppressed because it is too large Load Diff

7
test22 Normal file
View File

@ -0,0 +1,7 @@
1,0,1~1,2,1
0,0,2~2,0,2
0,2,3~2,2,3
0,0,4~0,2,4
2,0,5~2,2,5
0,1,6~2,1,6
1,1,8~1,1,9

40
zweiundzwanzig.py Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env python3
from useful import *
from rtree import index
def cubeize(line):
x, y, z, u, v, w = numbers(line)
return (x, y, z, u + 1, v + 1, w + 1)
def icall(tree):
ic([cube for cube in gtree.intersection((-666666, -666666, -666666, 666666, 666666, 666666))])
def move_touching_ground_to_ground():
global gtree, grounded, moving
touching = True
while touching:
touching = False
for i, m in enumerate(moving):
if list(gtree.intersection(m)):
del moving[i]
gtree.insert(len(grounded), m)
grounded += [m, ]
touching = True
break
unsortedcubes = [cubeize(l) for l in lines(open(0))]
cubeiter = iter(sorted(unsortedcubes, key=lambda a: a[2]))
# find the ones touching the ground... or just create the ground.
grounded = [(-666666, -666666, 0, 666666, 666666, 1)]
gtree = index.Index(properties=index.Property(dimension=3))
gtree.insert(0, grounded[0])
moving = [c for c in cubeiter]
ic(grounded, moving)
# also find the ones touching the ones touching ground
move_touching_ground_to_ground()
ic(grounded, moving)
icall(gtree)