Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local r = require("robot")
- -- functions part
- function move(dir, times)
- if dir == "f" then
- for i=1,times do
- r.forward()
- end
- elseif dir == "b" then
- for i=1,times do
- r.back()
- end
- elseif dir == "u" then
- for i=1,times do
- r.up()
- end
- elseif dir == "d" then
- for i=1,times do
- r.down()
- end
- elseif dir == "l" then
- r.turnLeft()
- elseif dir == "r" then
- r.turnRight()
- elseif dir == nil then
- print("You added ',' after the final move.")
- else
- print("Error in input!")
- os.exit()
- end
- end
- function convert(inp)
- t = {}
- c = 1
- for s, e in (inp..","):gmatch("(.)(.?.?),") do
- t[c] = {}
- t[c][1] = s
- t[c][2] = e
- c = c + 1
- end
- return t
- end
- function parse(inp)
- for i=1,#inp do
- move(inp[i][1], inp[i][2])
- end
- end
- -- work part
- path = "f1,d2,f1,r,f10,l,f3,d3,l,f3,d3,r,f5,r"
- parse(convert(path))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement