Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear, Documented and a golf version as bonus solution in Clear category for Square Board by Ylliw
from typing import Tuple
Coordinate = Tuple[int, int]
def square_board(side: int, token: int, steps: int) -> Coordinate:
# We will everywhere count in 'side-1', so let's do this first
side-=1
# position = (starting pos + moves) % length*4
pos = (token +steps)%(4*side)
# Time to convert the position number into coordinates
# Coordinates are different depending on which side we are on
# Side 0 to 3 correspond to pos/side as an integer so pos//side
return [(side,side-pos),(2*side-pos,0),(0,pos-2*side),(pos-3*side,side)][pos//side]
# Alternatively, a golf version could be:
# square_board=lambda s,t,i:(lambda l,p:[(l,l-p),(2*l-p,0),(0,p-2*l),(p-3*l,l)][p//l])(s-1,(t+i)%(4*s-4))
Feb. 14, 2019
Comments: