torus.lua

                Never    
Lua
       
local robot = require("robot")
local slot = 1

image0 = {
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111",
    "11111111111111111111111111111111"
}

image1 = {
    "00000000000000000000000000000000",
    "00000000000000000000000000000000",
    "00000000000000000000000000000000",
    "00000000000000000000000000000000",
    "00000000000011111111000000000000",
    "00000000001111111111110000000000",
    "00000000111111111111111100000000",
    "00000001111111111111111110000000",
    "00000011111111000011111111000000",
    "00000011111100000000111111000000",
    "00000111111000000000011111100000",
    "00000111110000000000001111100000",
    "00001111100000000000000111110000",
    "00001111100000000000000111110000",
    "00001111000000000000000011110000",
    "00001111000000000000000011110000",
    "00001111000000000000000011110000",
    "00001111000000000000000011110000",
    "00001111100000000000000111110000",
    "00001111100000000000000111110000",
    "00000111110000000000001111100000",
    "00000111111000000000011111100000",
    "00000011111100000000111111000000",
    "00000011111111000011111111000000",
    "00000001111111111111111110000000",
    "00000000111111111111111100000000",
    "00000000001111111111110000000000",
    "00000000000011111111000000000000",
    "00000000000000000000000000000000",
    "00000000000000000000000000000000",
    "00000000000000000000000000000000",
    "00000000000000000000000000000000"
}

image2 = {
    "00000000000000000000000000000000",
    "00000000000000000000000000000000",
    "00000000000011111111000000000000",
    "00000000001111111111110000000000",
    "00000000111100000000111100000000",
    "00000001110000000000001110000000",
    "00000011000000000000000011000000",
    "00000110000000000000000001100000",
    "00001100000000111100000000110000",
    "00001100000011111111000000110000",
    "00011000000111000011100000011000",
    "00011000001100000000110000011000",
    "00110000011000000000011000001100",
    "00110000011000000000011000001100",
    "00110000110000000000001100001100",
    "00110000110000000000001100001100",
    "00110000110000000000001100001100",
    "00110000110000000000001100001100",
    "00110000011000000000011000001100",
    "00110000011000000000011000001100",
    "00011000001100000000110000011000",
    "00011000000111000011100000011000",
    "00001100000011111111000000110000",
    "00001100000000111100000000110000",
    "00000110000000000000000001100000",
    "00000011000000000000000011000000",
    "00000001110000000000001110000000",
    "00000000111100000000111100000000",
    "00000000001111111111110000000000",
    "00000000000011111111000000000000",
    "00000000000000000000000000000000",
    "00000000000000000000000000000000"
}

image3 = {
    "00000000000000000000000000000000",
    "00000000000001111110000000000000",
    "00000000001110000001110000000000",
    "00000000110000000000001100000000",
    "00000001000000000000000010000000",
    "00000110000000000000000001100000",
    "00000100000000000000000000100000",
    "00001000000000000000000000010000",
    "00010000000000000000000000001000",
    "00010000000000000000000000001000",
    "00100000000000111100000000000100",
    "00100000000011000011000000000100",
    "00100000000100000000100000000100",
    "01000000000100000000100000000010",
    "01000000001000000000010000000010",
    "01000000001000000000010000000010",
    "01000000001000000000010000000010",
    "01000000001000000000010000000010",
    "01000000000100000000100000000010",
    "00100000000100000000100000000100",
    "00100000000011000011000000000100",
    "00100000000000111100000000000100",
    "00010000000000000000000000001000",
    "00010000000000000000000000001000",
    "00001000000000000000000000010000",
    "00000100000000000000000000100000",
    "00000110000000000000000001100000",
    "00000001000000000000000010000000",
    "00000000110000000000001100000000",
    "00000000001110000001110000000000",
    "00000000000001111110000000000000",
    "00000000000000000000000000000000"
}

image4 = {
    "00000000000000000000000000000000",
    "00000000000111111111100000000000",
    "00000000011000000000011000000000",
    "00000001100000000000000110000000",
    "00000010000000000000000001000000",
    "00000100000000000000000000100000",
    "00001000000000000000000000010000",
    "00010000000000000000000000001000",
    "00010000000000000000000000001000",
    "00100000000000000000000000000100",
    "00100000000000011000000000000100",
    "01000000000001100110000000000010",
    "01000000000010000001000000000010",
    "01000000000100000000100000000010",
    "01000000000100000000100000000010",
    "01000000001000000000010000000010",
    "01000000001000000000010000000010",
    "01000000000100000000100000000010",
    "01000000000100000000100000000010",
    "01000000000010000001000000000010",
    "01000000000001100110000000000010",
    "00100000000000011000000000000100",
    "00100000000000000000000000000100",
    "00010000000000000000000000001000",
    "00010000000000000000000000001000",
    "00001000000000000000000000010000",
    "00000100000000000000000000100000",
    "00000010000000000000000001000000",
    "00000001100000000000000110000000",
    "00000000011000000000011000000000",
    "00000000000111111111100000000000",
    "00000000000000000000000000000000"
}

image5 = {
    "00000000000001111110000000000000",
    "00000000001110000001110000000000",
    "00000000110000000000001100000000",
    "00000011000000000000000011000000",
    "00000100000000000000000000100000",
    "00001000000000000000000000010000",
    "00010000000000000000000000001000",
    "00010000000000000000000000001000",
    "00100000000000000000000000000100",
    "00100000000000000000000000000100",
    "01000000000000000000000000000010",
    "01000000000000111100000000000010",
    "01000000000001000010000000000010",
    "10000000000010000001000000000001",
    "10000000000100000000100000000001",
    "10000000000100000000100000000001",
    "10000000000100000000100000000001",
    "10000000000100000000100000000001",
    "10000000000010000001000000000001",
    "01000000000001000010000000000010",
    "01000000000000111100000000000010",
    "01000000000000000000000000000010",
    "00100000000000000000000000000100",
    "00100000000000000000000000000100",
    "00010000000000000000000000001000",
    "00010000000000000000000000001000",
    "00001000000000000000000000010000",
    "00000100000000000000000000100000",
    "00000011000000000000000011000000",
    "00000000110000000000001100000000",
    "00000000001110000001110000000000",
    "00000000000001111110000000000000"
}

image6 = {
    "00000000000011111111000000000000",
    "00000000011100000000111000000000",
    "00000001100000000000000110000000",
    "00000010000000000000000001000000",
    "00000100000000000000000000100000",
    "00001000000000000000000000010000",
    "00010000000000000000000000001000",
    "00100000000000000000000000000100",
    "00100000000000000000000000000100",
    "01000000000000000000000000000010",
    "01000000000000000000000000000010",
    "01000000000000111100000000000010",
    "10000000000001000010000000000001",
    "10000000000010000001000000000001",
    "10000000000100000000100000000001",
    "10000000000100000000100000000001",
    "10000000000100000000100000000001",
    "10000000000100000000100000000001",
    "10000000000010000001000000000001",
    "10000000000001000010000000000001",
    "01000000000000111100000000000010",
    "01000000000000000000000000000010",
    "01000000000000000000000000000010",
    "00100000000000000000000000000100",
    "00100000000000000000000000000100",
    "00010000000000000000000000001000",
    "00001000000000000000000000010000",
    "00000100000000000000000000100000",
    "00000010000000000000000001000000",
    "00000001100000000000000110000000",
    "00000000011100000000111000000000",
    "00000000000011111111000000000000"
}

local torus = {image0, image0, image1, image2, image3, image4, image5, image6, image5, image4, image3, image2, image1}

function up()
    local can, type = robot.detectUp()
    if (can)
    then
        robot.swingUp()
    end
    robot.up()
end

function forward()
    local can, type = robot.detect()
    if (can)
    then
        robot.swing()
    end
    robot.forward()
end

function checkSlot()
    local count = robot.count(slot)
    if (count == 0) then
        slot = slot + 1
        if (slot > 16) then
			slot = 1
		end
        checkSlot()
    end
    robot.select(slot)
end

function placeDown()
    local can, type = robot.detectDown()
    if (can)
    then
        robot.swingDown()
    end
    checkSlot()
    robot.placeDown()
end

function placeLayer (layer)
    for i = 1,32,1 do
        line = layer[i]
        for j = 1,32,1 do
            forward()
            byte = string.byte(line, j)
            if (byte == 49) then
                placeDown()
            end
        end
        forward()
        if (i % 2 == 0) then
            robot.turnRight()
        else
            robot.turnLeft()
        end
        forward()
        if (i % 2 == 0) then
            robot.turnRight()
        else
            robot.turnLeft()
        end
    end
    robot.turnRight()
    for i = 1, 32, 1 do
        forward()
    end
    robot.turnLeft()
end

for i = 3, 14, 1 do
    local layer = torus[i]
    placeLayer(layer)
    up()
end

Raw Text