Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

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. A navigation app that finds you a route shouldn't send you the long way around 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

  1. 1

    Get the dog to the goal.

  2. 2

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

Back

7/7

  1. 1. What Is an Algorithm
  2. 2. Turning
  3. 3. Left or Right?
  4. 4. Planning the Route
  5. 5. Finding Bugs
  6. 6. Collecting Bones
  7. 7. The Shortest Way
Next

Try it yourself

Do this exercise right here in your browser. No account needed.