Skip to content

Instantly share code, notes, and snippets.

@bluepapa32
Created August 16, 2011 10:34
Show Gist options
  • Save bluepapa32/1148823 to your computer and use it in GitHub Desktop.
Save bluepapa32/1148823 to your computer and use it in GitHub Desktop.
お題:FizzBuzz(Nパターン)
def fizzbuzz(from, to, list) {
def i = 0
def dict = list.split{ i++ % 2 == 0 }.transpose()
(from..to).each {
n -> println "${n}: ${dict.inject(''){ s, v -> (n % v[0] == 0) ? s + v[1] : s }}"
}
}
fizzbuzz(1, 100, [3, "Fizz", 5, "Buzz", 7, "Hoge"])
@bluepapa32
Copy link
Author

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