



































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




































Which II!is II!a II!valid II!Karel II!command? move; II! MOVE move(); II! move() II!- II! II!Correct II!Answers II!move(); II!What II!is II!a II!street II!in II!a II!Karel II!world? II!- II! II!Correct II!Answers II!Row II!What II!is II!an II!avenue II!in II!a II!Karel II!world? II!- II! II!Correct II!Answers II!Column II!IfII!Karel II!starts II!at II!Street II! 1 II!and II!Avenue II! 3 II!facing II!East, II!what II!street II!(row) II!and II!avenue II!(column) II!will II!Karel II!be II!on II!after II!this II!code II!runs? move(); move(); move(); turnLeft(); move(); II!- II! II!Correct II!Answers II!Street II! 2 II!Avenue II! 6 II!IfII!Karel II!is II!facing II!North II!and II!the II!code II! turnLeft(); turnLeft(); runs; II!which II!direction II!is II!Karel II!facing II!now? II!- II! II!Correct II!Answers II!South II!How II!many II!times II!should II!Karel II!turn II!left II!in II!order II!toII!turn II!right? II!- II! II!Correct II!Answers II! 3
II!What II!can II!be II!used II!toII!teach II!Karel II!to II!turn II!right? II!- II! II!Correct II!Answers II!functions II!Which II!function II!will II!teach II!Karel II!how II!toII!spin II!in II!a II!circle II!one II!time? function II!spin() II!{ II!turnRight(); } function II!spin() II!{ II!turnLeft(); II!turnLeft(); II!turnLeft(); II!turnLeft(); } function II!spin() II!{ II!turnLeft(); II!turnLeft(); } function II!spin() II!{ II!move(); II!move(); II!move(); II!move(); } II!- II! II!Correct II!Answers II!function II!spin() II!{ II!turnLeft(); II!turnLeft(); II!turnLeft(); II!turnLeft(); }
makeSide(); function II!makeSide(){ II!move(); II!putBall(); II!move(); II!putBall(); II!move(); II!putBall(); } goHome(); function II!goHome(){ II!turnRight(); II!move(); II!putBall(); II!move(); II!putBall(); II!move(); II!putBall(); II!turnLeft(); II!turnLeft(); II!turnLeft(); II!move(); II!move(); II!move(); II!turnLeft(); II!turnLeft(); }
II!2.5.4: II!Pancakes II!with II!Start II!- II! II!Correct II!Answers II!function II!start(){ II!move(); II!makePancakes(); II!move(); II!move(); II!makePancakes(); II!move(); II!move(); II!makePancakes(); II!move(); } function II!makePancakes(){ II!putBall(); II!putBall(); II!putBall(); } II!2.6.4: II!The II!Two II!Towers II!- II! II!Correct II!Answers II!function II!start(){ II! II!move(); II!turnLeft(); II!makeTower(); II!move(); II!turnRight(); II!move(); II!move(); II!turnRight(); II!move();
II!turnAround(); II!putBallsInRow(); } // II!Puts II!down II!four II!balls II!in II!a II!row function II!putBallsInRow(){ II!move(); II!putBall(); II!move(); II!putBall(); II!move(); II!putBall(); II!move(); II!putBall(); } function II!makeDiagonal(){ II!turnRight(); II!move(); II!turnRight(); II!move(); II!putBall(); II! II!turnLeft(); II!move(); II!turnRight(); II!move(); II!putBall();
II!turnLeft(); II!move(); II!turnRight(); II!move(); } function II!turnRight(){ II!turnLeft(); II!turnLeft(); II!turnLeft(); } function II!turnAround(){ II!turnLeft(); II!turnLeft(); } II!2.6.6: II!Reflection: II!Top II!Down II!Design II!- II! II!Correct II!Answers II!Top II!down II!design II!is II!a II!way II!of II!designing II!your II!program II!by II!starting II!with II!the II!biggest II!problem II!and II!breaking II!it II!down II!intoII!smaller II!and II!smaller II!pieces II!that II!are II!easier II!toII!solve. II!2.7.4: II!The II!Two II!Towers II!+ II!Comments II!- II! II!Correct II!Answers II!/* II!* II!Karel II!is II!going II!to II!make II!towers II!*/ II! II!function II!start(){ II! II!move(); II!turnLeft(); II!makeTower();
II! } II!Which II!answer II!choice II!describes II!the II!game II!with II!the II!lowest II!level II!of II!abstraction? II!- II! II!Correct II!Answers II!First, II!Steph II!Curry II!flexed II!his II!left II!and II!right II!quad II!muscles II!at II!the II!exact II!same II!time, II!then II!he II!flexed II!each II!muscle II!in II!his II!fingers... II!Karel II!needs II!toII!pick II!up II!a II!pile II!of II!tennis II!balls. Which II!of II!the II!following II!start II!functions II!solves II!the II!problem II!at II!the II!highest II!level II!of II!abstraction? II!- II! II!Correct II!Answers II!function II!start() II!{ II!moveToPile(); II!takePile(); } II!2.8.4: II!Abstracting II!Your II!Day II!- II! II!Correct II!Answers II!I II!made II!this: II!Its II!dumb II!don't II!blame II!me. II!(Basic II!101)
Example: Less II!-> II!Well II!I II!played II!GTA II! 6 II!today. II!I II!know II!it II!is II!not II!released II!yet, II!but II!I II!got II!to II!have II!a II!chance II!to II!play II!it II!on II!the II!Asus II!PC II!that II!has II!RTX II! 2080 II!ti II!graphics II!that II!are II!in II!sli. II!Meaning II!I II!got II!buttery II!smooth II!games, II!and II!lets II!not II!start II!talking II!about II!the II!4k II!resolution. II!Well II!I II!first II!was II!pumped II!toII!play II!a II!unreleased II!game. II!Second, II!I II!got II!handed II!the II!controller II!from II!my II!admin II!who II!was II!at II!the II!convention II!hosting II!the II!GTA II! 6 II!gameplay II!feed. II!Then II!I II!started II!toII!"grind" II!and II!play II!some II!missions. II!Soon II!my II!fingers II!went II!from II!relaxed II!toII!"gaming II!mode" II!and II!I II!felt II!as II!ifII!I II!was II!in II!the II!game. ~ II!This II!did II!not II!happen. II!:D II!2.8.6: II!Abstraction II!in II!Karel II!- II! II!Correct II!Answers II!Abstraction II!helps II!us II!write II!programs II!by: When II!we II!want II!to II!create II!something II!such II!as II!a II!function/command II!we II!need II!to II!explain II!it II!in II!detail. II!Meaning II!we II!need II!to II!add II!less II!abstraction II!to II!help II!us II!understand II!the II!command II!in II!a II!simpler II!way. II! Less II!Abstraction: II!Less II!abstracted II!- II!Abstract II!art. II!Less II!abstract II!more II!details. More II!Abstraction: II!More II!abstracted II!- II!Abstract II!art. II!More II!abstract II!less II!details. II!2.9.4: II!The II!Two II!Towers II!+ II!SuperKarel II!- II! II!Correct II!Answers II!function II!start(){ II!//Karel II!will II!build II!twoII!towers II!move(); II! II!turnLeft(); II! II!makeTower(); II!move(); II! II!turnRight(); II!move(); II! II!move(); II! II!turnRight(); II!move(); II! II!makeTower(); II! II!turnLeft(); II!turnLeft(); II!move(); II!
II!2.5.5: II!Digging II!Karel II!with II!Start II!- II! II!Correct II!Answers II!function II!start(){ II!move(); II!buryBall(); II!move(); II!buryBall(); II!move(); II!buryBall(); } function II!turnRight() II!{ II!turnLeft(); II!turnLeft(); II!turnLeft(); } function II!buryBall() II!{ II!move(); II!turnRight(); II!move(); II!move(); II!move(); II!putBall(); II!turnLeft(); II!turnLeft(); II!move(); II!move(); II!move(); II!turnRight(); II!move();
II!2.10.7: II!For II!Loop II!Square II!- II! II!Correct II!Answers II!function II!run(){ II! II!for(var II!i II!= II!0; II!i II!< II!4; II!i++){ II!putBall(); II!move(); II!turnLeft(); II!} } function II!start(){ II!run(); } II!2.10.8: II!Lots II!of II!Hurdles II!- II! II!Correct II!Answers II!function II!jumpHurdle(){ II!for(var II!i II!= II!0; II!i II!< II!5; II!i++){ II!move(); II!move(); II!turnLeft(); II!move(); II!turnRight(); II!move(); II!turnRight(); II!move(); II!turnLeft(); II!} } function II!start(){ II!jumpHurdle(); }
II!2.11.5: II!Is II!There II!a II!Ball? II!- II! II!Correct II!Answers II!function II!start(){ II! II!safeTakeBall(); II!putBall(); II!move(); } function II!safeTakeBall(){ II!if(ballsPresent()){ II!takeBall(); II!} } II!2.12.5: II!Right II!Side II!Up II!- II! II!Correct II!Answers II!function II!start(){ II!if(facingSouth()){ II!turnLeft(); II!}else{ II!turnRight(); II!turnRight(); II!} } II!2.13.4: II!Follow II!The II!Yellow II!Ball II!Road II!- II! II!Correct II!Answers II!function II!start() II!{ II!while II!(ballsPresent()) II!{ II!move(); II!} } II!2.13.5: II!Lay II!Row II!of II!Tennis II!Balls II!- II! II!Correct II!Answers II!function II!start(){ II!while II!(frontIsClear()) II!{
II!putBall(); II!move(); II!} II!putBall(); } II!2.13.6: II!Big II!Tower II!- II! II!Correct II!Answers II!function II!start(){ II!faceNorth(); II!buildTower(); II!putBall(); } II! //This II!function II!make II!Karel II!face II!north II!is II!Karel II!is II!facing II!west. function II!faceNorth(){ II!if(facingWest()){ II!turnRight(); II!} II!if(facingEast()){ II!turnLeft(); II!} II! II!if(facingSouth()){ II!turnLeft(); II!turnLeft(); II!} } //This II!function II!makes II!Karel II!put II!the II!tennis II!balls II!up II!to II!the II!top II!ofII!the II!"world". II! function II!buildTower(){ II!while(frontIsClear()){
II!move(); II!} II! II!turnLeft(); II!while(frontIsClear()){ II!if(rightIsBlocked()){ II!putBall(); II!move(); II!while(rightIsClear()){ II!move(); II!} II!} II!if(frontIsBlocked()){ II!putBall(); II!} II!} } II!2.16.4: II!Diagonal II!- II! II!Correct II!Answers II!//This II!program II!has II!karel II!lay II!a II!diagonal II!row II!of II!tennis II!balls. II!However, II!the II!indenting II!is II!all II!wrong. function II!start(){ II!while(frontIsClear()){ II!putBall(); II!move(); II!turnLeft(); II!move(); II!for(var II!i II!= II!0; II!i II!< II!3; II!i++){
II!turnLeft(); II!} II!} II!putBall(); } II!2.16.5: II!Staircase II!- II! II!Correct II!Answers II!/* II!This II!program II!creates II!a II!staircase II!from II!the II!first II!spot II!all II!the II!* II!way II!across II!the II!world II!for II!any II!sized II!world. II!* II!This II!program II!works, II!but II!its II!indentation II!is II!completely II!wrong. II!* II! II!* II!Run II!the II!program II!first, II!so II!you II!know II!what II!it II!does II!and II!don't II!break II!it. II!*/ function II!start(){ II!putBall(); II!while(frontIsClear()){ II!turnLeft(); II!while II!(ballsPresent()) II!{ II!move(); II!} II!turnRight(); II!move(); II!createStep(); II!} } function II!createStep() II!{ II!turnRight(); II!putBall(); II!while II!(frontIsClear()) II!{