Last active
August 14, 2021 02:02
-
-
Save azurast/5fd3a413e5d23444578c85d423506da4 to your computer and use it in GitHub Desktop.
Jumping on Clouds - Swift
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
var c: [Int] = [0, 0, 1, 0, 0, 1, 0] | |
print("array \(c)") | |
var numberOfJumps = 0 | |
var i = 0 | |
while i < c.count { | |
if (i < c.count-1) { | |
print("i \(i)") | |
if (i < c.count-2) { | |
if (c[i+2] == 0) { | |
// jump twice | |
i += 2 | |
} else if (c[i+1] == 0) { | |
// jump once | |
i += 1 | |
} | |
} else { | |
if (c[i+1] == 0) { | |
// jump once | |
i += 1 | |
} | |
} | |
numberOfJumps += 1 | |
} else { | |
break | |
} | |
} | |
print("numberOfJumps \(numberOfJumps)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment