Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
divmod solution in Clear category for Square Board by Sim0000
from typing import Tuple
Coordinate = Tuple[int, int]
def square_board(side: int, token: int, steps: int) -> Coordinate:
s = side - 1
q, r = divmod((token + steps) % (4 * s), s)
return [(s, s - r), (s - r, 0), (0, r), (r, s)][q]
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!")
Feb. 8, 2019
Comments: