1) Karel should keep turning left until he is facing east. After that, he will turn left one more time. If you are facing east and you turn left, you will be facing north (a)
2) I don't know what a beeper is and what pickBeeper() does. If we assume that it doesn't affect where and how Karel moves, then we have the following:
part a: we will move forward one square (presumably) at a time, 6 times
part b: we will turn left
part c: we will repeat part a and b 4 times
So you end up walking in a big square, with each side being 6 grid squares long. You'll end up in the exact same spot where you started and facing the same direction.
3) method1 is just a repeat of part 2), but that's not really important. The important part is looking at where exactly the pickBeeper() call is in every method. For method1() it's in the inner-most loop, which means it will be called 6*4 = 24 times. In other words, we have a task that includes picking a beeper, we repeat that task 6 times as part of a bigger task, and we repeat that bigger task 4 times.
If that still doesn't make sense, think of it this way: let's say a bus fare costs $1. You have to take the bus to work and back every day (so 2 bus rides a day). You go to work 5 days a week. How much money will you spend on buses every week? As a nested loop like the ones you have, it would be represented like this:
Code
calculateWeeklyBusCost(){
iterate 5 times{
iterate 2 times{
payForBus();
}
}
}
so for method2, you only pick a beeper in the outer loop, so you'll end up with 6 beepers. You are in essence only picking up beepers at the corners of the big square that you are walking.
for method3, you are walking a tiny square of 1x1. So even though you are moving and picking beepers a lot of times (24), you'll only have 4 beepers at the end because you'll pick them all up and then you'll just keep going over the same empty grid.
This post was edited by russian on Oct 30 2015 10:31am