Skip to content

Instantly share code, notes, and snippets.

@edigreat
Last active December 26, 2015 22:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edigreat/7221437 to your computer and use it in GitHub Desktop.
Save edigreat/7221437 to your computer and use it in GitHub Desktop.
FizzBuzz with Groovy
class FizzBuzz {
String isPrintable ( divisor1=3, divisor2=5, number ) {
(number % (divisor1 * divisor2) == 0) ? "FIZZBUZZ" :
(number % divisor2 == 0) ? "BUZZ":
(number % divisor1 == 0) ? "FIZZ": "$number"
}
Map calcula(List lista){
if(lista.size()==1)
["${lista.head()}":isPrintable(lista.head())]
else
["${lista.head()}":isPrintable(lista.head())] + calcula(lista.tail())
}
}
def mapa =new FizzBuzz().calcula(1..100)
println mapa
@edigreat
Copy link
Author

edigreat commented Nov 6, 2013

Ejercicio FizzBuzz en groovy , uso de recursvidad y curry

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