This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
NewerOlder