Skip to content

Latest commit

 

History

History
67 lines (63 loc) · 1.57 KB

2.4.3 addFast.md

File metadata and controls

67 lines (63 loc) · 1.57 KB

2.4.3 addFast

void addFast() {
    repeat (8) {
        if (onBeeper()) {
            moveForward();
            if (onBeeper() && beeperAhead()) {
                // 1 + 1 + 1
                moveForward();
                moveForward();
                dropBeeper();
                nextWithCarry();
            } else if (!onBeeper() && !beeperAhead()) {
                // 1 + 0 + 0
                moveForward();
                moveForward();
                dropBeeper();
                nextWithoutCarry();
            } else {
                // 1 + 1 + 0 OR 1 + 0 + 1
                moveForward();
                moveForward();
                nextWithCarry();
            }
        } else {
            moveForward();
            if (onBeeper() && beeperAhead()) {
                // 1 + 1
                moveForward();
                moveForward();
                nextWithCarry();
            } else if (!onBeeper() && !beeperAhead()) {
                // 0 + 0
                moveForward();
                moveForward();
                nextWithoutCarry();
            } else {
                // 1 + 0 OR 0 + 1
                moveForward();
                moveForward();
                dropBeeper();
                nextWithoutCarry();
            }
        }
        
        moveForward();
        moveForward();      
        turnAround();  
    }
}

void nextWithoutCarry() {
    turnRight();
    moveForward();
    turnRight();
    moveForward();
}

void nextWithCarry() {
    turnRight();
    moveForward();
    turnRight();
    moveForward();
    dropBeeper();
}