Created
March 25, 2015 00:49
-
-
Save bdkosher/fb28a47e2b6397077500 to your computer and use it in GitHub Desktop.
Groovy FizzBuzz with CompileStatic.
This file contains hidden or 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
| @groovy.transform.CompileStatic | |
| List<String> fizzbuzz(int from = 1, int to = 100) { | |
| String f = 'fizz', b = 'buzz' | |
| def m = {int x, int y -> | |
| x % y == 0 | |
| } | |
| def F = { int n -> | |
| m(n,15) ? "$f$b" : m(n,3) ? f:m(n,5) ? b : n | |
| } | |
| (from..to).collect {int i -> F(i) } | |
| } | |
| fizzbuzz() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment