Skip to content

Instantly share code, notes, and snippets.

@mosampaio
Created October 25, 2013 17:44
Show Gist options
  • Save mosampaio/7158790 to your computer and use it in GitHub Desktop.
Save mosampaio/7158790 to your computer and use it in GitHub Desktop.
Recursive factorial in Groovy
def factorial
factorial = { it > 1 ? it * factorial(it-1) : it }
factorial(1) // 1
factorial(2) // 2
factorial(3) // 6
factorial(4) // 24
factorial(5) // 120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment