Skip to content

Instantly share code, notes, and snippets.

@sathish316
Created September 22, 2012 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sathish316/3764940 to your computer and use it in GitHub Desktop.
Save sathish316/3764940 to your computer and use it in GitHub Desktop.
Rover golf
D,N,E,S,W,R,L,M=%w{NESW y+=1 x+=1 y-=1 x-=1 d+=1 d-=1 e.(D[d%4])}
r=->(x,y,d,s){e=->(a){eval eval(a)};s.scan(/./){|a|e.(a)};[x,y,D[d%4]]}
p r.(1,2,D.index('N'),"LMLMLMLMM")
p r.(3,3,D.index('E'),"MMRMMRMRRM")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment