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,40 +72,37 @@ 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:
|
||||||
|
res, right, l, r = explode(right, lvl)
|
||||||
if not res:
|
if not res:
|
||||||
res, right, l, r = explode(right, lvl+1)
|
return False, n, None, None
|
||||||
if not res:
|
if l:
|
||||||
return False, n, None, None
|
if isinstance(left, int):
|
||||||
|
left = left + l
|
||||||
|
l = None
|
||||||
else:
|
else:
|
||||||
if l:
|
res, left = explode_to_left(left, l)
|
||||||
if isinstance(left, int):
|
if res:
|
||||||
left = left + l
|
l = None
|
||||||
l = None
|
return True, (left, right), l, r
|
||||||
else:
|
if r:
|
||||||
res, left = explode_to_left(left, l)
|
if isinstance(right, int):
|
||||||
if res:
|
right = right + r
|
||||||
l = None
|
r = None
|
||||||
return True, (left, right), l, r
|
|
||||||
else:
|
else:
|
||||||
if r:
|
res, right = explode_to_right(right, r)
|
||||||
if isinstance(right, int):
|
if res:
|
||||||
right = right + r
|
r = None
|
||||||
r = None
|
return True, (left, right), l, r
|
||||||
else:
|
|
||||||
res, right = explode_to_right(right, r)
|
|
||||||
if res:
|
|
||||||
r = None
|
|
||||||
return True, (left, right), l, r
|
|
||||||
|
|
||||||
|
|
||||||
def split(n):
|
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)
|
||||||
if not res:
|
if not res:
|
||||||
|
|||||||
Reference in New Issue
Block a user