diff --git a/dominic/pairing.lua b/dominic/pairing.lua new file mode 100644 index 0000000..c0e1fd0 --- /dev/null +++ b/dominic/pairing.lua @@ -0,0 +1,64 @@ +function pair(x, y) + return math.floor((x + y) * (x + y + 1)/2 + y) +end + +function unpairX(z) + local j = math.floor(math.sqrt(0.25 + 2*z) - 0.5) + return j - (z - j*(j+1)/2) +end + + +function unpairZ(z) + local j = math.floor(math.sqrt(0.25 + 2*z) - 0.5) + return z - j * (j+1)/2; +end + +lookup = {4, 1, 3, 0, 2} +local function isDiggingSpot(x, y) + local val = lookup[(y % 5) + 1] + return (x % 5) == val +end + +offset = 10 +function ithSpot(i) + j = offset + while true do + x, z = unpairX(j), unpairZ(j) + if isDiggingSpot(x, z) then + if i <= 1 then + return x, z + else + i = i - 1 + end + end + j = j + 1 + end +end + +function digTo(x, z) + while z > 0 do + turtle.dig() + turtle.forward() + turtle.digUp() + z = z - 1 + end + turtle.turnRight() + while x > 0 do + turtle.dig() + turtle.forward() + turtle.digUp() + x = x - 1 + end + +function digSpot(i) + x, z = ithSpot(i) + digTo(x, z) + turtle.digDown() + turtle.down() +end + +args = {...} +spotnum = tonumber(args[1]) +if spotnum then + digSpot(spotNum) +end