Assignment 1 - Problem 4

Starting Position & Final Position

As an exercise in solving algorithmic problems, program Karel to place a single beeper at the center of 1st Street.

Note that the final configuration of the world should have only a single beeper at the midpoint of 1st Street.  Along the way, Karel is allowed to place additional beepers wherever it wants to, but must pick them all up again before it finishes.

In solving this problem, you may count on the following facts about the world:

  • Karel starts at 1st Avenue and 1st Street, facing east, with an infinite number of beepers in its bag.
  • The initial state of the world includes no interior walls or beepers.
  • The world need not be square, but you may assume that it is at least as tall as it is wide.

Your program, moreover, can assume the following simplifications:

  • If the width of the world is odd, Karel must put the beeper in the center square. If the width is even, Karel may drop the beeper on either of the two center squares.
  • It does not matter which direction Karel is facing at the end of the run.

My solution:

Assignment 1 - Problem 3

In this exercise, your job is to get Karel to create a checkerboard pattern of beepers inside an empty rectangular world, as illustrated in the following before-and-after diagram.

  • Must work in all worlds, odd, even and one row.
  • Karels final location and the final direction it is facing at end of the ron do not matter.

Okay, so I spent the last couple of days trying to crack this nut going back and forth like crazy until I finally got it figured out, and I have to admit it was way more difficult than first expected. I guess programming never was easy :)

Anyways, heres the code. I know it’s shitty but it does the job and works on all words last time I checked. If you guys sovled the problem any differently I would really appreciate if you sent me the code so I can take a look at it.