This commit is contained in:
basicbonobo 2024-01-09 01:18:49 +01:00
parent 7a50a1543a
commit 3a1407b3b3
1 changed files with 20 additions and 12 deletions

View File

@ -51,7 +51,19 @@ vals = [values(l) for l in bot]
print( sum(check(v, 'in') for v in vals))
def split_single(low, hi, comp, pivot):
return [(low, hi), ()]
if comp == '>': # n > pivot?
if low > pivot:
return [(low, hi), ()]
if hi > pivot:
return [(pivot + 1, hi), (low, pivot + 1)]
return [(), (low, hi)]
elif comp == '<': # should always be true now. n < pivot?
if hi < pivot:
return [(low, hi), ()]
if low < pivot:
return [(low, pivot), (pivot, hi)]
return [(), (low, hi)]
assert False
def split(xmas, test):
var, comp, pivot = test
@ -59,24 +71,20 @@ def split(xmas, test):
low, hi = xmas[index]
return (xmas[:index] + [ss, ] + xmas[index + 1:] for ss in split_single(low, hi, comp, pivot))
def checkrange(xmas, rulestogo):
ic(xmas, rulestogo)
if not all(xmas): # :(
return [[0, 0, 0, 0], ]
def checkrange(xmas, rulestogo, indent=0):
if len(sys.argv) > 1 and sys.argv[1] == '-v':
print('%s%s%s' % (' ' * indent * 2, xmas, rulestogo), file=sys.stderr)
rule = rulestogo[0]
if rule == 'A':
return [[r - l for (l, r) in xmas], ]
if rule == 'R':
return [[0, 0, 0, 0], ]
if len(rulestogo) == 1: # or rule is str etc
return checkrange(xmas, flows[rule])
if len(rulestogo) == 1:
return checkrange(xmas, flows[rule], indent + 1)
test, target = rule
yes, no = split(xmas, test)
return checkrange(yes, [target, ]) + checkrange(no, rulestogo[1:])
return checkrange(yes, [target, ], indent + 1) + checkrange(no, rulestogo[1:], indent + 1)
# lower inclusive, upper exclusive makes everything easier
r = checkrange([(1, 4001), (1, 4001), (1, 4001), (1, 4001)], flows['in'])
ic(r)
a = np.asarray(r)
ic(a)
ic(a.sum(axis=0).prod())
print(np.asarray(r).prod(axis=1).sum())