Created
August 14, 2019 22:40
-
-
Save caesaneer/b15d0efe161a15eeb519294d210e3a8c to your computer and use it in GitHub Desktop.
Loop with Fibonacci Sequence
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 fibonacci() []int { | |
var result []int | |
var start = 1000 | |
for { | |
var num = 1250 | |
var n1, n2, temp int = 0, 1, 0 | |
for { | |
temp = n2 | |
n2 = n1 + n2 | |
n1 = temp | |
result = append(result, n2) | |
if num <= 1 { | |
break | |
} | |
num-- | |
} | |
if start <= 1 { | |
break | |
} | |
start-- | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment