Skip to content

Instantly share code, notes, and snippets.

@imbradmiller
Last active October 11, 2025 15:59
Show Gist options
  • Save imbradmiller/438fa0459ef5bc14cef77ee1f203ecb5 to your computer and use it in GitHub Desktop.
Save imbradmiller/438fa0459ef5bc14cef77ee1f203ecb5 to your computer and use it in GitHub Desktop.
Random Gems Everywhere
let totalGems = randomNumberOfGems
var gemCon = 0
func navigate () {
while !isBlocked {
moveForward()
if isOnGem {
collectGem()
gemCon += 1
}
}
}
func turnOffPortals() {
bluePortal.isActive = false
pinkPortal.isActive = false
}
func turnOnPortals() {
bluePortal.isActive = true
pinkPortal.isActive = true
}
func turnAround() {
turnRight()
turnRight()
}
while gemCon < totalGems {
navigate()
turnAround()
turnOffPortals()
navigate()
turnAround()
turnOnPortals()
}
@fzlittlerabbit
Copy link

fzlittlerabbit commented Oct 11, 2025

Here is my solution. I assume the Gems would appear on the edge as well, so I believe it is a more generic solution. But it always takes a long time to solve the puzzle. Don't know how to simplify it.

`
let totalGems = randomNumberOfGems
var countGem = 0

func navigate() {
if isBlockedRight && !isBlocked {
moveForward()
} else if !isBlockedRight {
turnRight()
moveForward()
} else if isBlocked{
turnLeft()
turnLeft()
}
}

func portalOpen() {
bluePortal.isActive = true
pinkPortal.isActive = true
}

func portalClose(){
bluePortal.isActive = false
pinkPortal.isActive = false
}

func collect(){
if isOnGem {
collectGem()
countGem = countGem + 1
}

}

while countGem != totalGems{
navigate()
portalClose()
collect()
navigate()
portalOpen()
collect()
}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment