Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Square Board by Elena_Korljukova
from typing import Tuple
Coordinate = Tuple[int, int]
def square_board(side: int, token: int, steps: int) -> Coordinate:
m = side - 1
n = token + steps
while not 0 <= n < 4*m:
n += 4*m if n < 0 else -4*m
if n in (a1 := [i for i in range(m, -1, -1)]):
x, y = m, a1.index(n)
elif n in (a2 := [i for i in range(2*m, m - 1, -1)]):
x, y = a2.index(n), 0
elif n in (a3 := [i for i in range(2*m, 3*m + 1)]):
x, y = 0, a3.index(n)
elif n in (a4 := [i for i in range(3*m, 4*m)] + [0]):
x, y = a4.index(n), m
return (x, y)
if __name__ == '__main__':
print("Example:")
print(square_board(4, 1, 4))
assert square_board(4, 1, 4) == (1, 0)
assert square_board(6, 2, -3) == (4, 5)
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 2, 2020