Limpie un poco el codigo
This commit is contained in:
@@ -8,23 +8,15 @@ def binary_partition(bsp, r):
|
||||
|
||||
half = (r[1] + r[0]) // 2
|
||||
|
||||
if bsp[0] in ['F', 'L']: r = (r[0], half)
|
||||
elif bsp[0] in ['B', 'R']: r = (half + 1, r[1])
|
||||
if bsp[0] in ['F', 'L']: return binary_partition(bsp[1:], (r[0], half))
|
||||
elif bsp[0] in ['B', 'R']: return binary_partition(bsp[1:], (half + 1, r[1]))
|
||||
|
||||
return binary_partition(bsp[1:], r)
|
||||
|
||||
def from_binary(bsp):
|
||||
"""
|
||||
Apparently doing a binary partition as the
|
||||
problem describes is the same as reading
|
||||
the instructions in binary
|
||||
"""
|
||||
#Apparently doing a binary partition as the problem describes is the same as reading
|
||||
#the instructions in binary, i think is in someway equivalent to the traversal of a binary tree
|
||||
|
||||
number = []
|
||||
for l in bsp:
|
||||
if l in ['F', 'L']: number.append('0')
|
||||
elif l in ['B', 'R']: number.append('1')
|
||||
return int("".join(number), 2)
|
||||
return int(bsp.replace('F', '0').replace('L', '0').replace('B', '1').replace('R', '1'), 2)
|
||||
|
||||
def get_id(row, col): return row * 8 + col
|
||||
|
||||
|
||||
Reference in New Issue
Block a user