examples/fibonacci: fix off-by-one fibonacci
authorTony Gaetani <tony.gaetani@gmail.com>
Fri, 27 May 2016 09:07:52 +0000 (11:07 +0200)
committerTony Gaetani <tony.gaetani@gmail.com>
Fri, 27 May 2016 09:07:52 +0000 (11:07 +0200)
Signed-off-by: Tony Gaetani <tony.gaetani@gmail.com>

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.