local function goBack(n)
  if n == nil then n = 1 end
  for i=1,n do
    while not turtle.back() do
      sleep(0.4)
    end
  end
end

local function placeAny()
  if not turtle.place() then
    for n=1,16 do
      if turtle.getItemCount(n) > 0 then
        turtle.select(n)
        if turtle.place() then
          return true
        end
      end
    end
  end
  return false
end

while true do
  placeAny()
  goBack(6)
end
