Created
November 6, 2011 13:28
-
-
Save yusuiked/1342875 to your computer and use it in GitHub Desktop.
Fibonacci sequence using recursion in the Groovy language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib(n) { | |
switch (n) { | |
case 0: 0; break | |
case 1..2: 1; break | |
default: n = fib(n-1) + fib(n-2); break | |
} | |
} | |
assert [0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987] == (0..16).collect {fib(it)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment