A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
6
Task/Fibonacci-sequence/Go/fibonacci-sequence-1.go
Normal file
6
Task/Fibonacci-sequence/Go/fibonacci-sequence-1.go
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
func fib(a int) int {
|
||||
if a < 2 {
|
||||
return a
|
||||
}
|
||||
return fib(a - 1) + fib(a - 2)
|
||||
}
|
||||
16
Task/Fibonacci-sequence/Go/fibonacci-sequence-2.go
Normal file
16
Task/Fibonacci-sequence/Go/fibonacci-sequence-2.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func fib(n uint64) *big.Int {
|
||||
if n < 2 {
|
||||
return big.NewInt(int64(n))
|
||||
}
|
||||
a, b := big.NewInt(0), big.NewInt(1)
|
||||
for n--; n > 0; n-- {
|
||||
a.Add(a, b)
|
||||
a, b = b, a
|
||||
}
|
||||
return b
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue