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 mineForward(n)
  if n == nil then n = 1 end
  for i=1,n do
    while not turtle.forward() do
      turtle.dig()
      while turtle.attack() do end
    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
  mineForward(1024)
end
