diff --git a/datastructures/recur.go b/datastructures/recur.go index 4e8edda..2cd11b8 100644 --- a/datastructures/recur.go +++ b/datastructures/recur.go @@ -1,5 +1,6 @@ package datastructures +// Factorial a function that computes the factorial or a number. Big (n) time and space complexity. For loop could use less memory. func Factorial(n int) int { if n < 1 { return 1 @@ -7,3 +8,11 @@ func Factorial(n int) int { return n * Factorial(n-1) } + +func Fib(n int) int { + if n < 1 { + return 1 + } + + return Fib(n-1) + Fib(n-2) +} diff --git a/learn_go_with_tests/my_context/go.mod b/learn_go_with_tests/my_context/go.mod new file mode 100644 index 0000000..991755f --- /dev/null +++ b/learn_go_with_tests/my_context/go.mod @@ -0,0 +1,3 @@ +module my_context + +go 1.23.1