Last active
September 15, 2022 07:11
-
-
Save benjaminpadula/f32b624f132342a436ac83f46e8b4d13 to your computer and use it in GitHub Desktop.
Swift Playgrounds: Roll Right, Roll Left Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while !isOnOpenSwitch { | |
while !isBlocked { | |
if isOnGem { | |
collectGem() | |
} | |
if isOnClosedSwitch { | |
toggleSwitch() | |
} | |
moveForward() | |
} | |
if isBlockedRight || isOnClosedSwitch { | |
turnLeft() | |
} | |
if isBlockedLeft || isOnGem { | |
turnRight() | |
} | |
} |
Great solution. You could simplify by removing the last isOnGem since all gems are in a corner.
if isBlockedLeft { turnRight() }
great work
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From Swift Playgrounds Learn to Code final challenge. I searched online, but didn’t find any elegant solutions, so I decided to post my own. I’d be happy to hear your thoughts/suggestions/questions.