begin 22
This commit is contained in:
parent
9c41bbdb37
commit
44d78ccdc6
|
@ -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
|
|
@ -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)
|
Loading…
Reference in New Issue