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

Planning the Route

Great, now you can walk and turn. But the longer the path, the easier it is to get a block wrong, and the dog ends up in a hedge. That's why programmers plan a program before they write it.

Imagine guiding a friend over the phone. "Come to me" isn't enough; you have to describe every part of the way: "Walk two steps straight ahead. Turn right. Walk two steps…" You have to guide the dog the same way. It can't see the green tile; it only knows the steps you give it.

How to do it:

  1. Trace the path on the screen with your finger, from the dog to the goal.
  2. Split it into straight sections. Count how many tiles each section has.
  3. At every corner, say which way the dog is facing and whether it should turn left or right.
  4. Only now build the blocks, section by section. You can run the program before it's finished to check that the first sections work.

Breaking a big task into smaller parts that are easy to solve is one of a programmer's most important skills. It's called decomposition.

Instructions

  1. 1

    Plan the route and get the dog to the goal. The path has five straight sections.

Back

4/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.