From 4c9e1bd4264f2594f588992377b25120fbb0646d Mon Sep 17 00:00:00 2001 From: Mihalis Tsoukalos Date: Wed, 15 Jan 2020 08:52:40 +0200 Subject: [PATCH] fibo3 with 0 returns 0 --- ch11/benchmarkMe.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ch11/benchmarkMe.go b/ch11/benchmarkMe.go index a9524a2..40ca3e0 100644 --- a/ch11/benchmarkMe.go +++ b/ch11/benchmarkMe.go @@ -25,7 +25,9 @@ func fibo3(n int) int { fn := make(map[int]int) for i := 0; i <= n; i++ { var f int - if i <= 2 { + if i == 0 { + f = 0 + } else if i <= 2 { f = 1 } else { f = fn[i-1] + fn[i-2] @@ -36,6 +38,10 @@ func fibo3(n int) int { } func main() { + fmt.Println(fibo1(0)) + fmt.Println(fibo2(0)) + fmt.Println(fibo3(0)) + fmt.Println(fibo1(40)) fmt.Println(fibo2(40)) fmt.Println(fibo3(40))