Skip to content

Instantly share code, notes, and snippets.

@bdkosher
Created March 25, 2015 00:49
Show Gist options
  • Select an option

  • Save bdkosher/fb28a47e2b6397077500 to your computer and use it in GitHub Desktop.

Select an option

Save bdkosher/fb28a47e2b6397077500 to your computer and use it in GitHub Desktop.
Groovy FizzBuzz with CompileStatic.
@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