3.2.4: super cleanup karel. i need a way to get karel back in place but i dont know how
/* Karel will clean up whole map, regardless of size
*/
function start() {
cleanAvenue();
while(frontIsClear()) {
cleanAvenue();
}
cleanAvenue();
}
function cleanAvenue() {
if(ballsPresent()) {
takeBall();
}
turnLeft();
while(frontIsClear()) {
move();
if(ballsPresent()) {
takeBall();
}
}
turnAround();
while(frontIsClear()) {
move();
if(ballsPresent()) {
takeBall();
}
}
if(leftIsClear()) {
turnLeft();
}
if(frontIsClear()) {
move();
}
} < thats what i have so far

Respuesta :

Answer:

/*This will make karel take all the balls in a world and

*end up back in its original location and it will face

*south when it is complete.

*/

function start() {

   ballsTaken();

   while(leftIsClear()){

       endUpFacingEast();

       ballsTaken();

       if(rightIsClear()){

           endUpFacingWest();

           ballsTaken();

       }else{

           turnAround();

       }

   }

}

function ballsTaken(){

   if(ballsPresent()){

       takeBall();

   }

   while(frontIsClear()){

       move();

       if(ballsPresent()){

           takeBall();

       }

   }

}

function endUpFacingEast(){

   turnLeft();

   move();

   turnLeft();

}

function endUpFacingWest(){

   turnRight();

   move();

   turnRight();

}

Explanation:

try this

ACCESS MORE
EDU ACCESS