Sha256: 65278828b53167d61c44ed06136b87fa040ce2ecc9d2199c691fe22236580472

Contents?: true

Size: 960 Bytes

Versions: 396

Compression:

Stored size: 960 Bytes

Contents

local commands = {
  R = {
    north = function(self) self.heading = 'east' end,
    east = function(self) self.heading = 'south' end,
    south = function(self) self.heading = 'west' end,
    west = function(self) self.heading = 'north' end
  },
  L = {
    north = function(self) self.heading = 'west' end,
    west = function(self) self.heading = 'south' end,
    south = function(self) self.heading = 'east' end,
    east = function(self) self.heading = 'north' end
  },
  A = {
    north = function(self) self.y = self.y + 1 end,
    east = function(self) self.x = self.x + 1 end,
    south = function(self) self.y = self.y - 1 end,
    west = function(self) self.x = self.x - 1 end
  }
}

local function move(self, command_chain)
  for command in command_chain:gmatch('.') do
    commands[command][self.heading](self)
  end
end

return function(config)
  return {
    x = config.x,
    y = config.y,
    heading = config.heading,
    move = move
  }
end

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.0.0.5 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.0.0.4 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.0.0.3 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.0.0.2 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.0.0.1 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.0.0.0 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.4.1 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.4.0 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.3.0 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.2.1 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.2.0 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.1.2 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.1.1 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.1.0 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.0.1 tracks/lua/exercises/robot-simulator/example.lua
trackler-1.0.0 tracks/lua/exercises/robot-simulator/example.lua