Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created August 26, 2010 17:10
Show Gist options
  • Save nobeans/551790 to your computer and use it in GitHub Desktop.
Save nobeans/551790 to your computer and use it in GitHub Desktop.
fact = { n ->
isEnd = n <= 1
work = isEnd ? 1 : fact(n - 1)
result = n * work as long
}
max = args[0] as long
range = 1..max
range.each { num ->
fact num
println "$num! => $result"
}
@nobeans
Copy link
Author

nobeans commented Aug 26, 2010

$ perl -e '$_=join//,@ARGV;print s/[(){}\[\]]//g||0' `cat factorial.groovy`
8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment