Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fzlittlerabbit/e9e06cc7978b4ba0dbe3d8ce852a8f9f to your computer and use it in GitHub Desktop.
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.
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