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