This commit is contained in:
basicbonobo 2023-12-26 16:38:08 +01:00
parent ce47b76682
commit 4abc996e0f
2 changed files with 14 additions and 16 deletions

View File

@ -34,11 +34,11 @@ def dprint(*args):
sep = False
for arg in args:
if sep:
print('--------')
print('--------', file=sys.stderr)
sep = True
for a, b in arg.items():
print('%10s: %s' % (a, ','.join(str(bb) for bb in b)))
print()
print('%10s: %s' % (a, ','.join(str(bb) for bb in b)), file=sys.stderr)
print(file=sys.stderr)
def pp(twod):
for r in twod:

View File

@ -4,9 +4,6 @@ from useful import *
from rtree import index
def hush(l):
return reduce(lambda a, b: a + chr(64 | b >> 5) + chr(64 | b & 63), l, '')
def cubeize(line):
x, y, z, u, v, w = numbers(line)
return (x, y, z, u + .9, v + .9, w + 1)
@ -54,17 +51,18 @@ while len(moving):
ic(grounded, moving)
icall(gtree)
# count stuff
d = defaultdict(lambda: [])
# count stuff. there must be a better way.
supporting = {}
supporters = defaultdict(lambda: 0)
for i, g in enumerate(grounded):
if i == 0: # our own fake box
continue
supporting = [m for m in gtree.intersection(g) if grounded[m][2] > g[2]]
for s in supporting:
d[hush([s,])] += [i, ]
if not supporting:
d[''] += [i, ]
supported = [m for m in gtree.intersection(g) if grounded[m][2] > g[2]]
supporting[i] = supported
for s in supported:
supporters[s] += 1
#print('%s (%s) is resting on %s!' % (supporting, hush(supporting), i))
dprint(d)
print([v for k, v in d.items() if k == '' or len(v) > 1])
print(len(set(c for c in collapse(v for k, v in d.items() if k == '' or len(v) > 1))))
dprint(supporting)
ic(supporters)
print(sum(1 for k, v in supporting.items() if \
all(supporters[vv] > 1 for vv in v)))