Skip to content

Instantly share code, notes, and snippets.

@plombardi89
Created August 29, 2014 01:39
Show Gist options
  • Save plombardi89/4bd7d13b1def7d61bfce to your computer and use it in GitHub Desktop.
Save plombardi89/4bd7d13b1def7d61bfce to your computer and use it in GitHub Desktop.
Recursive Fizzbuzz
// Performs the FizzBuzz test using recursion. I intend to use this more often when interviewing job candidates to find out if they
// even have a basic grasp of recursion.
def fizzbuzz(int max) {
fizzbuzz(1, max)
}
def fizzbuzz(int current, int max) {
if (current == max)
return
def out = ""
if (current % 3 == 0)
out += 'fizz'
if (current % 5 == 0)
out += 'buzz'
println (out ?: current)
fizzbuzz(current + 1, max)
}
fizzbuzz(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment