Skip to content

Instantly share code, notes, and snippets.

@yusuiked
Created November 6, 2011 13:28
Show Gist options
  • Save yusuiked/1342875 to your computer and use it in GitHub Desktop.
Save yusuiked/1342875 to your computer and use it in GitHub Desktop.
Fibonacci sequence using recursion in the Groovy language.
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