Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
modulo solution in Clear category for Square Board by kurosawa4434
from typing import Tuple
Coordinate = Tuple[int, int]
def square_board(side: int, token: int, steps: int) -> Coordinate:
dif = ((0, -1), (-1, 0), (0, 1), (1, 0))
quarter = side - 1
y, x = quarter, quarter
coords = [(y, x)]
for n in range(quarter*4-1):
dy, dx = dif[n // quarter]
y += dy
x += dx
coords.append((y, x))
return coords[(token+steps) % (quarter*4)]
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!")
Jan. 26, 2019