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.2.1.180 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.179 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.178 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.177 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.176 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.175 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.174 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.173 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.172 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.171 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.170 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.169 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.167 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.166 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.165 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.164 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.163 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.162 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.161 tracks/lua/exercises/robot-simulator/example.lua
trackler-2.2.1.160 tracks/lua/exercises/robot-simulator/example.lua