boolean beeperWorthySetting { //determine wether a beeper stack is to be processed boolean returnValue; turnLeft(); move(); if (rightIsClear()) returnValue = false; else returnValue = true; turnLeft(); turnLeft(); move(); turnLeft(); return returnValue; } void processStack { turnLeft(); //take all beppers, and count them for later use int i; while nextToABeeper{ pickBeeper(); i++; } //walk along the wall until reaching the first cleared on the right spot while (!rightIsClear()) move(); //drop all beepers but one for (i; i>1 ; i--) putBeeper(); //return to main line and head east turnLeft(); turnLeft(); while (frontIsClear()) move(); turnLeft(); } void endSequence { //return to (1,1) and head East turnLeft(); turnLeft(); while (frontIsClear()) move(); turnLeft(); turnLeft(); //drop l00t while (anyBeepersInBag()) putBeeper(); //go to sleep turnOff(); } main { //make sure that Karel is east-headed. while (!karel.facingEast()) karel.turnLeft( ); //get Karel to move until the front is blocked, checking for a beeper on each step and invoking the proper sequence of methods while (karel.frontIsClear) { karel.move(); if (karel.nextToABeeper()) { if (karel.beeperWorthySetting()) karel.processStack(); } karel.endSequence(); }