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,13 +72,12 @@ def explode(n, lvl=0):
(left, right) = n (left, right) = n
if lvl == 4 and isinstance(left, int) and isinstance(right, int): if lvl == 4 and isinstance(left, int) and isinstance(right, int):
return True, 0, left, right return True, 0, left, right
else: lvl += 1
res, left, l, r = explode(left, lvl+1) res, left, l, r = explode(left, lvl)
if not res: if not res:
res, right, l, r = explode(right, lvl+1) res, right, l, r = explode(right, lvl)
if not res: if not res:
return False, n, None, None return False, n, None, None
else:
if l: if l:
if isinstance(left, int): if isinstance(left, int):
left = left + l left = left + l
@@ -88,7 +87,6 @@ def explode(n, lvl=0):
if res: if res:
l = None l = None
return True, (left, right), l, r return True, (left, right), l, r
else:
if r: if r:
if isinstance(right, int): if isinstance(right, int):
right = right + r right = right + r
@@ -104,7 +102,6 @@ def split(n):
if isinstance(n, int): if isinstance(n, int):
if 10 <= n: if 10 <= n:
return True, (n // 2, (n + 1) // 2) return True, (n // 2, (n + 1) // 2)
else:
return False, n return False, n
(left, right) = n (left, right) = n
res, left = split(left) res, left = split(left)