local robot = require("robot")
robot.select(2)
if robot.count(1)<1 then
 print("place torch in slot 1")
 return
end
local l=0
while true do
 while robot.detect() do
  robot.swing()
 end
 if robot.forward() then l=l+1 end
 robot.swingDown()
 while robot.detectUp() do
  robot.swingUp()
 end
 if l>11 then
  l=0
  robot.select(1)
  robot.placeDown()
  if robot.count(1) < 1 then return end
  robot.select(2)
 end
 if robot.count(16)>0 then return end
end

Add a code snippet to your website: www.paste.org