Created
February 6, 2022 22:45
-
-
Save themarcelor/7273eb3ade5087ec469a3b8a93671efb to your computer and use it in GitHub Desktop.
silly fibonacci function in golang
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
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| func fib(num int) []int { | |
| prev, prevprev := 0, 1 | |
| result := []int{} | |
| for i:=0; i < num; i++ { | |
| prev, prevprev = prevprev, prev + prevprev | |
| result = append(result, prev) | |
| } | |
| return result | |
| } | |
| func main() { | |
| fmt.Printf("### the result: %v\n", fib(7)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment