본문 바로가기
Log/IDE

Day73_Karel 코딩 게임 답안

by uxia 2023. 11. 2.

재밌는 코딩 게임을 알아냈다

 

https://stanford.edu/~cpiech/karel/ide.html

 

Karel IDE

 

stanford.edu

 

스탠포드 대학에서 만들었다는데, 차근차근 풀 수 있게 돼있어서

코딩 모르는 사람도 배우면서 풀 수 있을 것 같다.

 

마지막 가면 코딩 배운 나도 어렵긴 한데,

그래도 재밌다.

 

 

 

 

앞부분은 그냥 퀴즈 풀듯이 하면 된다

 

 

Unit 3 Lesson 3

//change this program
//so that Karel moves
//three steps
function main(){
   move();
   move();
   move();
}

 

 

 

Unit 3 Lesson 4

//change this program
//so that Karel moves
//to the top of the
//ledge
function main(){
   turnLeft();
   move();
   turnLeft();
   turnLeft();
   turnLeft();
   move();
}

 

 

 

Unit 3 Lesson 5

//change this program
//so that Karel puts
//a beeper on each
//corner of the first
//row
function main(){
   putBeeper();
   move();
   putBeeper();
   move();
   putBeeper();
   move();
   putBeeper();
}

 

 

 

Unit 3 Lesson 6

//change this program
//so that Karel picks
//up all three beepers
function main() {
   move();
   pickBeeper();
   pickBeeper();
   pickBeeper();
   move();
}

 

 

 

Unit 4 Lesson 2

// Teach karel to turnAround

// This function teaches Karel 
// how to turn around.
function turnAround() {
   // your code here
   turnLeft();
   turnLeft();
}

function main(){
   move();
   putBeeper();
   turnAround();
   move();
   turnAround();
}

 

 

 

Unit 5 Lesson 1

//Make karel go outside and
//pick up the "newspaper"
function turnRight() {
   turnLeft();
   turnLeft();
   turnLeft();
}

function turnUpend() {
   turnLeft();
   turnLeft();
}

function main(){
   move();
   putBeeper();
   move();
   turnRight();
   move();
   turnLeft();
   move();
   pickBeeper();
   turnUpend();
   move();
   turnRight();
   move();
   turnLeft();
   move();
   move();
   turnUpend();
}

 

 

Unit 6 Lesson 2

//Make karel place 50 beepers

function place50Beepers() {
   repeat(50) {
      // your code here
      putBeeper();
   }
}

function main() {
   move();
   place50Beepers();
   move();  
}

 

 

 

Unit 8 Lesson 2

//Change this program so that
//Karel moves forward until
//she encounters a wall no
//matter how big the world is.
function main() {
   moveToWall();
}

function moveToWall(){
   while(frontIsClear()) {
      // you fill this in
      move();
   }
}

 

 

 

Unit 8 Lesson 3

//Karel tried to put a line
//of beepers but missed the
//first one. Help!
function main() {
   putBeeperLine();
   putBeeper();
}

function putBeeperLine(){
   while(frontIsClear()) {
      putBeeper();
      move();
   }
}

 

 

 

Unit 8 Lesson 5

//Make Karel fill the world
//with beepers
function main() {
   //your code here
   while (leftIsClear()) {
      putBeeperLine();
      resetPosition();
   }
   putBeeperLine();
}

function putBeeperLine(){
   putBeeper();
   while(frontIsClear()) {
      move();
      putBeeper();
   }
}

function resetPosition() {
   turnAround();
   while (frontIsClear()) {
      move();
   }
   turnRight();
   move();
   turnRight();
}

 

 

 

Unit 9 Lesson 2

//Karel must help rebuild 
//broken columns. Make a 
//column of beepers above
//each beeper you find on
//the first row
function main() {
   while(frontIsClear()){
      move();
      if (beepersPresent()) {
         turnLeft();
         while (frontIsClear()) {
            move();
            putBeeper();
         }
         getBack();
      }
   }
}

function turnAround() {
   turnLeft();
   turnLeft();
}

function getBack() {
   turnAround();
   while (frontIsClear()) {
      move();
   } 
   turnLeft();
}

 

 

 

Unit 10, 11 에러 있음

 

 

Unit 12 Lesson 1

//Your final task is to teach
//Karel to find the midpoint
//of any world. You can assume
//that all worlds are square.

function main() {
   markWalls();
	putBeepersDown();
	turnAround();
	move();
	putBeeper();
	turnAround();
	goToWall();
	turnAround();
	lastBeeperStanding();
}

//Karel moves to end walls, marking them with beepers

function markWalls() {
	goToWall();
	putBeeper();
	turnAround();
	goToWall();
	putBeeper();
	turnAround();
	move();
}

function goToWall() {
	while(frontIsClear()) {
		move();
	}
}


function putBeepersDown() {
	while(noBeepersPresent()) {
		move();
		if (beepersPresent()) {
			turnAround();
			move();
			putBeeper();
			move();
		}
	}
}

function lastBeeperStanding() {
	while (frontIsClear()) {
		if (beepersPresent()) {
			pickBeeper();
		}
		move();
	}
	pickBeeper();
}