Created
October 10, 2025 14:07
-
-
Save fzlittlerabbit/e9e06cc7978b4ba0dbe3d8ce852a8f9f to your computer and use it in GitHub Desktop.
I just started to learn coding via Swift Playground. I found this level is quite challenging, and I'd like to learn how to optimize the code.
This file contains hidden or 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
func toggleorcollect() { | |
if isOnGem { | |
collectGem() | |
} else if isOnClosedSwitch && isBlocked { | |
turnLeft() | |
toggleSwitch() | |
} else if isOnClosedSwitch{ | |
toggleSwitch() | |
} | |
} | |
func navigateAroundWall(){ | |
if !isBlocked { | |
moveForward() | |
} else if isBlockedRight { | |
turnLeft() | |
} else { | |
turnRight() | |
} | |
} | |
while !isOnOpenSwitch{ | |
toggleorcollect() | |
navigateAroundWall() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment