Skip to content

Instantly share code, notes, and snippets.

@plexus
Created July 29, 2014 12:28
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 plexus/2556baef03cb50e228bb to your computer and use it in GitHub Desktop.
Save plexus/2556baef03cb50e228bb to your computer and use it in GitHub Desktop.
bearings = {
north: ->(x,y) { [x+1, y] },
east: ->(x,y) { [x, y+1] },
south: ->(x,y) { [x-1, y] },
west: ->(x,y) { [x, y-1] }
}
bot = ->(x, y, bearing) do
{
coords: [x, y],
bearing: bearing,
step: -> do
bot.(*bearings[bearing].(x,y), bearing)
end
}
end
b = bot.(5, 5, :east) # => {:coords=>[5, 5], :bearing=>:east, :step=>#<Proc:0x00000001cffe58@-:12 (lambda)>}
b = b[:step].() # => {:coords=>[5, 6], :bearing=>:east, :step=>#<Proc:0x00000001cff7f0@-:12 (lambda)>}
b = b[:step].() # => {:coords=>[5, 7], :bearing=>:east, :step=>#<Proc:0x00000001cff250@-:12 (lambda)>}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment