1.18.4 Super Cleanup Karel
Question: Which is a valid Karel command?
move;
MOVE
move();
move()
Answer: move();
==================================================
Question: What is a street in a Karel world?
Answer: Row
==================================================
Question: What is an avenue in a Karel world?
Answer: Column
==================================================
Question: If Karel starts at Street 1 and Avenue 3 facing East, what street (row) and avenue (column) will Karel be on after this code runs?
move();
move();
move();
turnLeft();
move();
Answer: Street 2 Avenue 6
==================================================
Question: If Karel is facing North and the code
turnLeft();
turnLeft();
runs; which direction is Karel facing now?
Answer: South
==================================================
Question: How many times should Karel turn left in order to turn right?
Answer: 3
==================================================
Question: What can be used to teach Karel to turn right?
Answer: functions
==================================================
Question: Which function will teach Karel how to spin in a circle one time?
function spin() {
turnRight();
}
function spin() {
turnLeft();
turnLeft();
turnLeft();
turnLeft();
}
function spin() {
turnLeft();
turnLeft();
}
function spin() {
move();
move();
move();
move();
}
Answer: function spin() {
turnLeft();
turnLeft();
turnLeft();
turnLeft();
}
==================================================
Question: How many times should the start function be defined in a program?
Answer: 1
==================================================
Question: How many times should the start function be called in a program?
Answer: 0
==================================================
Question: Why do we use functions in programming?
Answer: Break down our program into smaller parts
Avoid repeating code
Make our program more readable
==================================================
Question: What is a top down design?
Answer: Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.
==================================================
Question: What is a code comment
Answer: A way to give notes to the reader to explain what your code is doing
==================================================
Question: What commands does SuperKarel know that regular Karel does not?
Answer: turnAround(); and turnRight();
==================================================
Question: Why should a programmer indent their code?
Answer: Helps show the structure of the code
Easier for other people to understand
Indenting is a key part of good programming style
==================================================
Question: 2.4.7 Building a Shelter Code
Answer: turnLeft();
makeSide();
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}
turnRight();
makeSide();
function makeSide(){
move();
putBall();
move();
putBall();
move();
putBall();
}
goHome();
function goHome(){
turnRight();
move();
putBall();
move();
putBall();
move();
putBall();
turnLeft();
turnLeft();
turnLeft();
move();
move();
move();
turnLeft();
turnLeft();
}
==================================================
Question: 2.5.4: Pancakes with Start
Answer: function start(){
move();
makePancakes();
move();
move();
makePancakes();
move();
move();
makePancakes();
move();
}
function makePancakes(){
putBall();
putBall();
putBall();
}
==================================================
Question: 2.6.4: The Two Towers
Answer: function start(){
move();
turnLeft();
makeTower();
move();
turnRight();
move();
move();
turnRight();
move();
makeTower();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
}
function makeTower(){
putBall();
move();
putBall();
move();
putBall();
}
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}
==================================================
Question: 2.6.5: Make a ‘Z’
Answer: function start(){
putBallsInRow();
makeDiagonal();
move();
turnAround();
putBallsInRow();
}
// Puts down four balls in a row
function putBallsInRow(){
move();
putBall();
move();
putBall();
move();
putBall();
move();
putBall();
}
function makeDiagonal(){
turnRight();
move();
turnRight();
move();
putBall();
turnLeft();
move();
turnRight();
move();
putBall();
turnLeft();
move();
turnRight();
move();
}
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}
function turnAround(){
turnLeft();
turnLeft();
}
==================================================
Question: 2.6.6: Reflection: Top Down Design
Answer: Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.
==================================================
Question: 2.7.4: The Two Towers + Comments
Answer: /*
Karel is going to make towers
*/
function start(){
move();
turnLeft();
makeTower();
move();
turnRight();
move();
move();
turnRight();
move();
makeTower();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
}
function makeTower(){
putBall();
move();
putBall();
move();
putBall();
}
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}
==================================================
Question: Which answer choice describes the game with the lowest level of abstraction?
Answer: First, Steph Curry flexed his left and right quad muscles at the exact same time, then he flexed each muscle in his fingers…
==================================================
Question: Karel needs to pick up a pile of tennis balls.
Which of the following start functions solves the problem at the highest level of abstraction?
Answer: function start() {
moveToPile();
takePile();
}
==================================================
Question: 2.8.4: Abstracting Your Day
Answer: I made this: Its dumb don’t blame me. (Basic 101)
I slipped on my shoes.
- I first had to put on socks. Then I used my right hand to pull the tag of the shoe so it can slip on.
- I first clapped down on the sock with both hands and gradually made it slide up my foot. Then I increased tension in my right hand so I can pull the tag of the shoe, when I got hold of the shoe. I relaxed my fingers except my pointer finger. And I pulled on the tag gently so the shoe can slip on.
I played COD (Call of Duty)
- I first took out the xbox controller and then I booted the xbox. After that I started to play COD.
- I first took the xbox controller off the counter with minimal effort of my muscles. Then I booted the xbox with my pointer finger. After that I sat down resting my glutes. Then I relaxed my fingers on the stick layout. And I started to play, after a while my fingers and my muscles started to get tense from all the action.
==================================================
Question: 2.8.5: Reflection: Abstraction
Answer: What is abstraction? Describe it in your OWN words.
For instance if I use less abstraction it is going to be easier to understand. Less abstract. Like the art. But if I use high abstraction then it is going to be harder to understand. Like it is just said, not explained.
Example:
Less -> Well I played GTA 6 today. I know it is not released yet, but I got to have a chance to play it on the Asus PC that has RTX 2080 ti graphics that are in sli. Meaning I got buttery smooth games, and lets not start talking about the 4k resolution. Well I first was pumped to play a unreleased game. Second, I got handed the controller from my admin who was at the convention hosting the GTA 6 gameplay feed. Then I started to “grind” and play some missions. Soon my fingers went from relaxed to “gaming mode” and I felt as if I was in the game.
~ This did not happen. :D
==================================================
Question: 2.8.6: Abstraction in Karel
Answer: Abstraction helps us write programs by:
When we want to create something such as a function/command we need to explain it in detail. Meaning we need to add less abstraction to help us understand the command in a simpler way.
Less Abstraction: Less abstracted - Abstract art. Less abstract more details.
More Abstraction: More abstracted - Abstract art. More abstract less details.
==================================================
Question: 2.9.4: The Two Towers + SuperKarelp
Answer: function start(){
//Karel will build two towers
move();
turnLeft();
makeTower();
move();
turnRight();
move();
move();
turnRight();
move();
makeTower();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
}
//This function will be used whenever Karel is supposed to build a tower
function makeTower() {
putBall();
move();
putBall();
move();
putBall();
}
==================================================
Question: 2.10.5: Take ‘em All
Answer: function run(){
move();
for(var i = 0; i < 100; i++){
takeBall();
}
move();
}
function start(){
run();
}
==================================================
Question: 2.10.6: Dizzy Karel
Answer: function run(){
for(var i = 0; i < 32; i++){
turnLeft();
}
}
==================================================
Question: 2.5.5: Digging Karel with Start
Answer: function start(){
move();
buryBall();
move();
buryBall();
move();
buryBall();
}
function turnRight() {
turnLeft();
turnLeft();
turnLeft();
}
function buryBall() {
move();
turnRight();
move();
move();
move();
putBall();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
move();
}
==================================================
Question: 2.10.7: For Loop Square
Answer: function run(){
for(var i = 0; i < 4; i++){
putBall();
move();
turnLeft();
}
}
function start(){
run();
}
==================================================
Question: 2.10.8: Lots of Hurdles
Answer: function jumpHurdle(){
for(var i = 0; i < 5; i++){
move();
move();
turnLeft();
move();
turnRight();
move();
turnRight();
move();
turnLeft();
}
}
function start(){
jumpHurdle();
}
==================================================
Question: 2.4.6 Digging Karel
Answer: buryBall();
move();
buryBall();
move();
buryBall();
move();
function buryBall(){
move();
move();
turnLeft();
turnLeft();
turnLeft();
move();
move();
move();
turnLeft();
putBall();
turnLeft();
move();
move();
move();
turnLeft();
turnLeft();
turnLeft();
}
==================================================
Question: 2.11.5: Is There a Ball?
Answer: function start(){
safeTakeBall();
putBall();
move();
}
function safeTakeBall(){
if(ballsPresent()){
takeBall();
}
}
==================================================
Question: 2.12.5: Right Side Up
Answer: function start(){
if(facingSouth()){
turnLeft();
}else{
turnRight();
turnRight();
}
}
==================================================
Question: 2.13.4: Follow The Yellow Ball Road
Answer: function start() {
while (ballsPresent()) {
move();
}
}
==================================================
Question: 2.13.5: Lay Row of Tennis Balls
Answer: function start(){
while (frontIsClear()) {
putBall();
move();
}
putBall();
}
==================================================
Question: 2.13.6: Big Tower
Answer: function start(){
faceNorth();
buildTower();
putBall();
}
//This function make Karel face north is Karel is facing west.
function faceNorth(){
if(facingWest()){
turnRight();
}
if(facingEast()){
turnLeft();
}
if(facingSouth()){
turnLeft();
turnLeft();
}
}
//This function makes Karel put the tennis balls up to the top of the “world”.
function buildTower(){
while(frontIsClear()){
putBall();
move();
}
}
==================================================
Question: 2.14.4: Random Hurdles
Answer: function start() {
//This makes Karel move to all the hurdles
for (var i = 0; i < 13; i++) {
if (frontIsBlocked()) {
jumpHurdle();
} else {
move();
}
}
}
function jumpHurdle() {
//This makes Karel jump over the hurdles
turnLeft();
move();
turnRight();
move();
turnRight();
move();
turnLeft();
}
==================================================
Question: 2.15.6: Decorate the Fence
Answer: function start(){
while(frontIsClear()){
move();
}
turnLeft();
while(frontIsClear()){
if(rightIsBlocked()){
putBall();
move();
while(rightIsClear()){
move();
}
}
if(frontIsBlocked()){
putBall();
}
}
}
==================================================
Question: 2.16.4: Diagonal
Answer: //This program has karel lay a diagonal row of tennis balls. However, the indenting is all wrong.
function start(){
while(frontIsClear()){
putBall();
move();
turnLeft();
move();
for(var i = 0; i < 3; i++){
turnLeft();
}
}
putBall();
}
==================================================
Question: 2.16.5: Staircase
Answer: /* This program creates a staircase from the first spot all the
way across the world for any sized world.
* This program works, but its indentation is completely wrong.
*
* Run the program first, so you know what it does and don’t break it.
*/
function start(){
putBall();
while(frontIsClear()){
turnLeft();
while (ballsPresent()) {
move();
}
turnRight();
move();
createStep();
}
}
function createStep() {
turnRight();
putBall();
while (frontIsClear()) {
move();
putBall();
}
turnLeft();
}
==================================================
Question: 2.17.5: Invert Colors
Answer: //update Oct.27.2018 10:44 I GOT IT!! BIGGEST GAY
start();
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
move();
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
move();
}
}
if(colorIs(Color.blue)){
paint(Color.red);
if(frontIsClear());
}else{
if(colorIs(Color.red)){
paint(Color.blue);
if(frontIsClear());
}
}
function start(){
}
==================================================
Question: 2.17.6: Checkerboard Karel
Answer: start();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnRight();
move();
turnRight();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnRight();
move();
turnRight();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnRight();
move();
turnRight();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
turnLeft();
move();
turnLeft();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.black);
move();
paint(Color.red);
LEEF();
function start(){
}
function LEEF(){
turnLeft();
move();
move();
move();
move();
move();
move();
move();
turnLeft();
}
==================================================
Question: 2.18.1: Fetch
Answer: function start() {
turnLeft();
move4();
turnRight();
move2();
takeBall();
move();
turnRight();
move4();
turnLeft();
move3();
gP();
move3();
move3();
gP();
putBall();
}
//allow move karel 4 times
function move4(){
move();
move();
move();
move();
}
function move2(){
move();
move();
}
function gP(){
turnLeft();
turnLeft();
}
function move3(){
move();
move();
move();
}
==================================================
Question: 2.18.2: Racing Karel
Answer: // This program will have Karel run around the racetrack 8 times.
function start(){
for(var i = 0; i < 32; i++){
setBall();
runToWall();
turnLeft();
}
}
function setBall(){
putBall();
}
function runToWall(){
while (frontIsClear()){
move();
}
}
==================================================
Question: 2.18.3: Tower Builder
Answer: //starts the tower
function start(){
buildTower();
while(frontIsClear()){
move();
safeMove();
}
}
function buildTower(){
turnLeft();
putBall();
move();
putBall();
move();
putBall();
turnAround();
move();
move();
turnLeft();
}
function safeMove(){
if(frontIsClear()){
move();
buildTower();
}
}
==================================================
Question: 2.18.4: Super Cleanup Karel
Answer: //3 functions made 1 start
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();
}
==================================================
Question: 2.18.5: Double Tennis Balls
Answer: //Have 5 functions 1 start
function start(){
move();
putTwoBalls();
moveBack();
}
function putTwoBalls(){
while(ballsPresent()){
takeBall();
putTwoMoreBallsNextAve();
}
moveBallsNextDoorBack();
}
function putTwoMoreBallsNextAve(){
move();
putBall();
putBall();
moveBack();
}
function moveBallsNextDoorBack(){
move();
while(ballsPresent()){
moveOneBallBack();
}
moveBack();
}
function moveOneBallBack(){
takeBall();
moveBack();
putBall();
move();
}
function moveBack(){
turnAround();
move();
turnAround();
}
==================================================
Question: 2.20.3: Planning
Answer: //This is going to be the function that decipher/tells Karel what to do
function start(){
move();
turnLeft();
makeTower();
move();
turnRight();
move();
move();
turnRight();
move();
makeTower();
turnLeft();
turnLeft();
move();
move();
move();
turnRight();
}
//This will make tower build a tower when said.
function makeTower(){
putBall();
move();
putBall();
move();
putBall();
}
//Not using Ultra Karel or SuperKarel this is what you should do.
function turnRight(){
turnLeft();
turnLeft();
turnLeft();
}
==================================================
Question: 2.20.4: Pseudocode
Answer: //Don’t copy this MAKE your own
MileStone 1:
First to build a tower:
Turn left
Then place a for loop:
putBall();
move();
putBall();
move();
putBall();
}
MileStone 2:
To come down:
Turn right //Because I am using “basic” Karel I have to make a function for that.
repeat 3 times
move
Turn left
}
MileStone 3:
Make function for make tower
//which is what the loop will be
putBall();
move();
putBall();
move();
putBall();
}
MileStone 4:
Make another function for basic Karel to turn Right
turnLeft();
turnLeft();
turnLeft();
}
MileStone 5:
Debug and run
==================================================
Question: 2.20.5: Create your UltraKarel…
Answer: function Twenty(){
paint(Color.red);
move();
paint(Color.orange);
move();
paint(Color.yellow);
move();
paint(Color.green);
move();
paint(Color.cyan);
move();
paint(Color.blue);
move();
paint(Color.purple);
move();
paint(Color.gray);
move();
paint(Color.white);
move();
paint(Color.black);
move();
paint(Color.red);
move();
paint(Color.orange);
move();
paint(Color.yellow);
move();
paint(Color.green);
move();
paint(Color.cyan);
move();
paint(Color.blue);
move();
paint(Color.purple);
move();
paint(Color.gray);
move();
paint(Color.white);
move();
paint(Color.black);
}
function start(){
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
turnRight();
move();
turnRight();
Twenty();
turnLeft();
move();
turnLeft();
Twenty();
}
==================================================
Question: 2.20.2: Brainstorm and Discuss
Answer: //Easy
Function Creator (Make Karel do a Backflip) (Then go around the perimeter.)
What is the project idea? What will you create?
This will show that you the difference from Ultra and Basic Karel.
What is the purpose of this project idea? Why do you want to make this?
The purpose should create a challenge that isn’t hard or easy. This pushes you create anything that still orders the Backflip and perimeter run.
What are some specific functions you’ll need to write to create this project?
function (If front is Blocked) Function (If Clear)
How long do you think this project will take to complete?
At least 45 minutes
==================================================
Question: 2.20.6: Reflection
Answer: //This is mine that connects with MY code. Use as reference.
For my program, I had used language of JavaScript to create it. The purpose of my program is to make a Karel make towers, while placing balls on each row/column. The game is also supposed to help you grow out of your zone and create more to it. (Open Source). When the creation of the Tower you can make Karel paint, turn around, do a backflip, etc. Abstraction helps, because it is easier to read the broken down code. Also, with the repeat/for loop function this cuts the code to be smaller and easier to understand. With debugging it took me at least 45 minutes. But next time I would add some cool/custom unique characteristics such as a rainbow border. This is possible with basic, Super, and Ultra Karel. Just takes some time to create something fundamental. Goal achieving project.
==================================================