Skip to main content
Home

Main navigation

  • Apps
  • Forum
  • Blog
    • Podcast
    • Guides
    • Hardware & Accessory Reviews
    • Bug Tracker
    • Developer Resources
  • Log in

Breadcrumb

  1. Home
  2. Forums
  3. iOS and iPadOS

Swift Playgrounds coding query

By Roy Towner, 29 December, 2016

Forum
iOS and iPadOS

I have just completed the 'which way to turn' puzzle using the following algorithm: if blocked turn left, else if blocked right move forward, else turn right, move forward. It works with this order of sequence but not if the order of the first two is reversed - which seems more logical in the context of the puzzle layout.

What is the explanation?

Options

  • Log in or register to post comments

Comments

Correct me if I'm wrong

By dvdmth

5 years 6 months ago

Club AppleVis Member

When I read your algorithm, this is what I interpreted:

1. If I cannot go forward, I should turn left.
2. If I can go forward, but cannot go right, then I should take a step forward.
3. If I can go forward, but can also go right, then I should turn right and take a step.

From looking at the puzzle, that appears to make sense.

If I reverse the first two steps in your logic, I get the following:

1. If I cannot go right, then I should take a step forward.
2. If I can go right, but cannot go forward, I should turn left.
3. If I can go right and can also go forward, then I should turn right and take a step.

This fails because I would attempt to go forward whenever the way to the right is blocked, regardless of whether or not the way forward is clear.

If I did not interpret your post correctly, let me know.

Another way

By Mani

5 years 6 months ago

If I misinterpreted your question , please forgive me . I just thought of a simple way:

if blocked-right and blocked-left
take a step forward
else if blocked-right
turn left
else turn right

More Like This

Swift Playgrounds On The Mac (Forum Topic)
Making Swift Playgrounds accessible (Forum Topic)
Swift Playgrounds and Xcode groups for the blind community (Forum Topic)
Any blind Swift Playground users on here (Forum Topic)
Learn to Code with Swift Playgrounds on iPad - Part 3 (Podcast)
Learn to Code with Swift Playgrounds on iPad - Part 2 (Podcast)
Learn to Code with Swift Playgrounds on iPad - Part 1 (Podcast)
my thoughts on the swift playgrounds app for iPad (Forum Topic)

Site Information

  • About
  • Club AppleVis
  • FAQ
  • Contact

Unless stated otherwise, all content is copyright AppleVis. All rights reserved. © 2022 | Accessibility | Terms | Privacy