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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great solution. You could simplify by removing the last isOnGem since all gems are in a corner.
if isBlockedLeft { turnRight() }