Replace 'type() is' with 'isinstance()'
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:
@@ -33,12 +33,12 @@ def parse(line):
|
||||
def explode_to_left(n, l):
|
||||
(left, right) = n
|
||||
res = True
|
||||
if type(right) == int:
|
||||
if isinstance(right, int):
|
||||
right = right + l
|
||||
else:
|
||||
res, right = explode_to_left(right, l)
|
||||
if not res:
|
||||
if type(left) == int:
|
||||
if isinstance(left, int):
|
||||
left = left + l
|
||||
res = True
|
||||
else:
|
||||
@@ -51,12 +51,12 @@ def explode_to_left(n, l):
|
||||
def explode_to_right(n, r):
|
||||
(left, right) = n
|
||||
res = True
|
||||
if type(left) == int:
|
||||
if isinstance(left, int):
|
||||
left = left + r
|
||||
else:
|
||||
res, left = explode_to_right(left, r)
|
||||
if not res:
|
||||
if type(right) == int:
|
||||
if isinstance(right, int):
|
||||
right = right + r
|
||||
res = True
|
||||
else:
|
||||
@@ -67,10 +67,10 @@ def explode_to_right(n, r):
|
||||
|
||||
|
||||
def explode(n, lvl=0):
|
||||
if type(n) is int:
|
||||
if isinstance(n, int):
|
||||
return False, n, None, None
|
||||
(left, right) = n
|
||||
if lvl == 4 and type(left) is int and type(right) is int:
|
||||
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)
|
||||
@@ -80,7 +80,7 @@ def explode(n, lvl=0):
|
||||
return False, n, None, None
|
||||
else:
|
||||
if l:
|
||||
if type(left) is int:
|
||||
if isinstance(left, int):
|
||||
left = left + l
|
||||
l = None
|
||||
else:
|
||||
@@ -90,7 +90,7 @@ def explode(n, lvl=0):
|
||||
return True, (left, right), l, r
|
||||
else:
|
||||
if r:
|
||||
if type(right) is int:
|
||||
if isinstance(right, int):
|
||||
right = right + r
|
||||
r = None
|
||||
else:
|
||||
@@ -101,7 +101,7 @@ def explode(n, lvl=0):
|
||||
|
||||
|
||||
def split(n):
|
||||
if type(n) is int:
|
||||
if isinstance(n, int):
|
||||
if 10 <= n:
|
||||
return True, (n // 2, (n + 1) // 2)
|
||||
else:
|
||||
@@ -116,11 +116,11 @@ def split(n):
|
||||
def magnitude(n):
|
||||
m = 0
|
||||
(left, right) = n
|
||||
if type(left) is int:
|
||||
if isinstance(left, int):
|
||||
m += 3 * left
|
||||
else:
|
||||
m += 3 * magnitude(left)
|
||||
if type(right) is int:
|
||||
if isinstance(right, int):
|
||||
m += 2 * right
|
||||
else:
|
||||
m += 2 * magnitude(right)
|
||||
|
||||
Reference in New Issue
Block a user