Tidy up explode function
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-12-18 20:50:09 +01:00
parent 66e344a5e5
commit 014d2947fe

View File

@@ -72,40 +72,37 @@ def explode(n, lvl=0):
(left, right) = n
if lvl == 4 and isinstance(left, int) and isinstance(right, int):
return True, 0, left, right
else:
res, left, l, r = explode(left, lvl+1)
lvl += 1
res, left, l, r = explode(left, lvl)
if not res:
res, right, l, r = explode(right, lvl)
if not res:
res, right, l, r = explode(right, lvl+1)
if not res:
return False, n, None, None
return False, n, None, None
if l:
if isinstance(left, int):
left = left + l
l = None
else:
if l:
if isinstance(left, int):
left = left + l
l = None
else:
res, left = explode_to_left(left, l)
if res:
l = None
return True, (left, right), l, r
res, left = explode_to_left(left, l)
if res:
l = None
return True, (left, right), l, r
if r:
if isinstance(right, int):
right = right + r
r = None
else:
if r:
if isinstance(right, int):
right = right + r
r = None
else:
res, right = explode_to_right(right, r)
if res:
r = None
return True, (left, right), l, r
res, right = explode_to_right(right, r)
if res:
r = None
return True, (left, right), l, r
def split(n):
if isinstance(n, int):
if 10 <= n:
return True, (n // 2, (n + 1) // 2)
else:
return False, n
return False, n
(left, right) = n
res, left = split(left)
if not res: