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

Turn Until the Path Is Ahead

This time, the dog starts in a dead end, facing a hedge. The way out is on its left on the first map, on its right on the second, and behind it on the third. The dog has to turn to face the way out and then walk to the goal.

What should it do? Turn as long as there's no path ahead:

  • Repeat while not path ahead
    • Turn left ↺

Before every pass, the dog looks ahead. While there's a hedge in front of it, it turns a quarter turn. As soon as it faces the path, the loop ends. On the first map, the dog turns once, on the third twice, and on the second three times: three quarter turns to the left leave it facing where one turn to the right would. The loop doesn't need to know where the way out is. The dog keeps turning until it faces it.

Without not, the dog would have to ask about each direction: if there's a path to the left, turn left, else if there's a path to the right, turn right, and else turn around. That's two questions and eight blocks. The loop asks one question and has four blocks: Repeat while, not, path ahead and Turn left ↺.

Then the dog walks to the goal. Look closely: the path goes on past the goal. So the dog has to stop at the goal, and Repeat while path ahead would take it past. Which loop stops at the goal?

Instructions

  1. 1

    Get the dog to the goal on all three maps: turn it with Repeat while not path ahead, then walk to the goal.

Back

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