mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
734 B
51 lines
734 B
5 years ago
|
## fibonacci
|
||
5 years ago
|
|
||
5 years ago
|
### Instructions
|
||
5 years ago
|
|
||
|
Write an **recursive** function that returns the value of fibonacci sequence matching the index passed as parameter.
|
||
|
|
||
|
The first value is at index `0`.
|
||
|
|
||
|
The sequence starts this way: 0, 1, 1, 2, 3 etc...
|
||
|
|
||
|
A negative index will return `-1`.
|
||
|
|
||
|
`for` is **forbidden** for this exercise.
|
||
|
|
||
5 years ago
|
### Expected function
|
||
5 years ago
|
|
||
|
```go
|
||
![]()
5 years ago
|
package piscine
|
||
5 years ago
|
|
||
5 years ago
|
func Fibonacci(index int) int {
|
||
5 years ago
|
|
||
|
}
|
||
|
```
|
||
|
|
||
5 years ago
|
### Usage
|
||
5 years ago
|
|
||
5 years ago
|
Here is a possible program to test your function :
|
||
5 years ago
|
|
||
|
```go
|
||
|
package main
|
||
|
|
||
|
import (
|
||
5 years ago
|
"fmt"
|
||
|
piscine ".."
|
||
5 years ago
|
)
|
||
|
|
||
|
func main() {
|
||
|
arg1 := 4
|
||
|
fmt.Println(piscine.Fibonacci(arg1))
|
||
|
}
|
||
|
```
|
||
|
|
||
|
And its output :
|
||
|
|
||
|
```console
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$ go build
|
||
|
student@ubuntu:~/[[ROOT]]/test$ ./test
|
||
5 years ago
|
3
|
||
5 years ago
|
student@ubuntu:~/[[ROOT]]/test$
|
||
5 years ago
|
```
|