The Shortest Way

A task often has more than one solution. Two paths lead to this goal: one around the top of the hedge, and a shorter one around the bottom. The dog gets to the goal along either of them, but the two programs aren't equally good:

  • along the shorter path, the dog takes fewer steps, so it gets to the goal sooner,
  • the program for the shorter path has fewer blocks, so it's easier to read and easier to find bugs in.

Programmers don't just check whether an algorithm works, but also how well: how many steps it takes and how long it is. The algorithm that finds a route in a satnav shouldn't send you the long way round either.

This exercise limits the number of blocks. Above the editor, you'll see how many blocks the program has and the most it may have. The Start block doesn't count.

Instructions

Get the dog to the goal.

The program may have at most 11 blocks. If it has more, choose the shorter path.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

7/7