Skip to content

Instantly share code, notes, and snippets.

@aderchox
Last active August 30, 2022 06:39
Show Gist options
  • Select an option

  • Save aderchox/9e8444d29c58a5ffa6bd605b5925e527 to your computer and use it in GitHub Desktop.

Select an option

Save aderchox/9e8444d29c58a5ffa6bd605b5925e527 to your computer and use it in GitHub Desktop.

Revisions

  1. aderchox revised this gist Aug 30, 2022. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions karel_secureTheCave
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    void secureTheCave(){
    turnLeft();
    repeat(10){
    goToEnd();
    turnAround();
    sweepBeepersToBottom();
    situateInTheNextColumn();
    }
    }

    void goToEnd(){
    while(frontIsClear()){
    moveForward();
    }
    }

    void sweepBeepersToBottom(){
    if(!onBeeper()){
    goToEnd();
    turnAround();
    } else {
    pickBeeper();
    moveForward();
    sweepBeepersToBottom();
    dropBeeper();
    moveForward();
    }
    }

    void situateInTheNextColumn(){
    turnRight();
    if(frontIsClear()){
    moveForward();
    turnLeft();
    }
    }
  2. aderchox created this gist Aug 30, 2022.
    79 changes: 79 additions & 0 deletions karel_addFast
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,79 @@
    /*
    0-0-0-0-1-1-1-1
    0-0-1-1-0-0-1-1
    0-1-0-1-0-1-0-1

    —-1-1-c-1-c-c-1c
    */

    void addFast(){
    repeat(8){
    addColumn();
    }
    }

    void addColumn(){
    if(!onBeeper() && !beeperAhead()){
    moveForward();
    if(beeperAhead()){
    /* Uncommenting the two lines below will make the job more beautiful, but will also unfortunately fail the tests */
    /* moveForward();
    pickBeeper(); */
    add1AtTheBottom();
    }
    moveEnd();
    moveToNextColumn();
    moveEnd();
    turnAround();
    }
    else if((onBeeper() && !beeperAhead())
    || (!onBeeper() && beeperAhead())){
    moveForward();
    if(beeperAhead()){
    dropCarry();
    } else {
    add1AtTheBottom();
    moveToNextColumn();
    }
    moveEnd();
    turnAround();
    } else {
    /* Both digits are 1 */
    moveForward();
    if(beeperAhead()){
    /* Uncommenting the two lines below will make the job more beautiful, but will also unfortunately fail the tests */
    /* moveForward();
    pickBeeper(); */
    add1AtTheBottom();
    dropCarry();
    } else {
    dropCarry();
    }
    moveEnd();
    turnAround();
    }
    }

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

    void moveEnd(){
    while(frontIsClear()){
    moveForward();
    }
    }

    void dropCarry(){
    moveEnd();
    moveToNextColumn();
    moveForward();
    dropBeeper();
    }

    void add1AtTheBottom(){
    moveEnd();
    dropBeeper();
    }