Skip to content

Commit

Permalink
Fixed Fibonacci example
Browse files Browse the repository at this point in the history
The check for n == 0 was missing.
  • Loading branch information
hardliner66 committed Apr 11, 2016
1 parent 1777e45 commit 045e41b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions std/functional.d
Original file line number Diff line number Diff line change
Expand Up @@ -1067,9 +1067,10 @@ unittest
{
ulong fib(ulong n)
{
return n <= 2 ? 1 : memoize!fib(n - 2) + memoize!fib(n - 1);
if (n == 0) return 0;
return n < 2 ? 1 : memoize!fib(n - 2) + memoize!fib(n - 1);
}
assert(fib(10) == 89);
assert(fib(10) == 55);
}

/**
Expand Down

0 comments on commit 045e41b

Please sign in to comment.