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

Bones Mark the Way

The dog is in a park where paths cross everywhere. At every crossroads, there's a path ahead, to the left and to the right, so the senses that look for paths can't tell the dog where to turn. They aren't among the blocks this time. Instead, the owner has marked the way with bones: at the first bone, the dog turns left, and at the second, right. Then it walks on to the goal. The bones are in different places on each map, but the order is always the same: first left, then right.

Would an If inside Repeat until at the goal do it? On every tile: if there's a bone here, pick it up and turn left. But that If would turn the dog the same way at every bone, left at the first and left at the second too. It can't tell the two bones apart. So there's no If among the blocks either.

Instead, split the walk into parts, one loop for each, one under another:

  1. Repeat while not bone here with Move forward inside takes the dog to the first bone. Pick it up and turn left.
  2. The same loop again takes it to the second bone. Pick it up and turn right.
  3. Repeat until at the goal with Move forward inside takes it to the goal.

Each loop ends where its part of the walk ends, and the next one goes on from there. The dog doesn't need to know which bone it's at: the order of the loops in the program tells it.

Instructions

  1. 1

    On all three maps, walk to the first bone, pick it up and turn left, then walk to the second bone and pick it up too.

  2. 2

    Turn right and walk to the goal.

Back

4/7

  1. 1. The Not Block
  2. 2. Turn Until the Path Is Ahead
  3. 3. Quiz: Repeat While Not
  4. 4. Bones Mark the Way
  5. 5. Take the First Right
  6. 6. Quiz: A Bug with Not
  7. 7. Summary
Next

Try it yourself

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