Tidy up explode function
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -72,13 +72,12 @@ 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+1)
|
||||
res, right, l, r = explode(right, lvl)
|
||||
if not res:
|
||||
return False, n, None, None
|
||||
else:
|
||||
if l:
|
||||
if isinstance(left, int):
|
||||
left = left + l
|
||||
@@ -88,7 +87,6 @@ def explode(n, lvl=0):
|
||||
if res:
|
||||
l = None
|
||||
return True, (left, right), l, r
|
||||
else:
|
||||
if r:
|
||||
if isinstance(right, int):
|
||||
right = right + r
|
||||
@@ -104,7 +102,6 @@ def split(n):
|
||||
if isinstance(n, int):
|
||||
if 10 <= n:
|
||||
return True, (n // 2, (n + 1) // 2)
|
||||
else:
|
||||
return False, n
|
||||
(left, right) = n
|
||||
res, left = split(left)
|
||||
|
||||
Reference in New Issue
Block a user