Jeroo

Problems

Visit every square

Start a single Jeroo in the top left corner (0,0). Hop east until water is reached then turn round and come back along the next row.

You could do this by writing a sequence of hops and turns but this would take a lot of instructions (how many?). It would be possible to copy and paste the code fairly quickly but programmers do not like this type of solution. They want the code to express their intentions in a more concise and elegant way.

One way to solve the problem is to use a while loop (or more than one). Write a while loop that moves a Jeroo until it meets the edge of the island (what is at the edge of the island?) Then the Jeroo should turn around and head back along the next row. Coming back will need a second while loop.

We could repeat the while loops 12 times each to visit every square on the island but once again a programmer would seek a more compact solution: another while loop wrapped around the other two.

The new while loop will need a condition to finish it. Unfortunately Jeroo does not include a way of identifying the location of the current square; a condition can only be based on a property of a square such as whether it contains something or is next to a square that contains something.

 

 

 

     
     
     
     
     
     
Web Resources:
     
     
     

Home Page