From 630fe8ee45c0a9ec3941344b819711c5e0a8e1e1 Mon Sep 17 00:00:00 2001 From: Drew Bednar Date: Sun, 10 Nov 2024 09:54:25 -0500 Subject: [PATCH] Saving current work --- datastructures/recur.go | 9 +++++++++ learn_go_with_tests/my_context/go.mod | 3 +++ 2 files changed, 12 insertions(+) create mode 100644 learn_go_with_tests/my_context/go.mod 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