Skip to content

Instantly share code, notes, and snippets.

View arocks's full-sized avatar

Arun Ravindran arocks

View GitHub Profile
import Data.List
dirs = "NESW"
shifts 0 = (0, 1)
shifts 1 = (1, 0)
shifts 2 = (0, -1)
shifts 3 = (-1, 0)
instrn (x, y, a) 'R' = (x, y, mod (a + 1) 4)
dirs = "NESW" # Notations for directions
shifts=[(0,1),(1,0),(0,-1),(-1,0)] # delta vector for each direction
# One letter function names corresponding to each robot instruction
r = lambda x, y, a: (x, y, (a + 1) % 4)
l = lambda x, y, a: (x, y, (a - 1 + 4) % 4)
m = lambda x, y, a: (x + shifts[a][0], y + shifts[a][1], a)
raw_input() # Ignore the grid size
while 1:
# parse initial position triplet
x, y, dir = raw_input().split()