Merge: examples/fibonacci: fix off-by-one fibonacci
authorJean Privat <jean@pryen.org>
Fri, 27 May 2016 18:48:02 +0000 (14:48 -0400)
committerJean Privat <jean@pryen.org>
Fri, 27 May 2016 18:48:02 +0000 (14:48 -0400)
Signed-off-by: Tony Gaetani <tony.gaetani@gmail.com>

Pull-Request: #2132
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/fibonacci.nit

index d4330ba..66cbfb0 100644 (file)
@@ -21,12 +21,9 @@ redef class Int
        # Calculate the self-th element of the fibonacci sequence.
        fun fibonacci: Int
        do
-               if self < 2 then
-                       return 1
-               else
-                       return (self-2).fibonacci + (self-1).fibonacci
-               end
-       end 
+               if self < 2 then return self
+               return (self-2).fibonacci + (self-1).fibonacci
+       end
 end
 
 # Print usage and exit.