Skip to content

Instantly share code, notes, and snippets.

@fumokmm
Created August 17, 2011 08:10
Show Gist options
  • Save fumokmm/1151077 to your computer and use it in GitHub Desktop.
Save fumokmm/1151077 to your computer and use it in GitHub Desktop.
お題:FizzBuzz(Nパターン) solved by Groovy
// http://d.hatena.ne.jp/fumokmm/20110815/1313405510
def fizzBuzzN(nums, list) {
def toMap = { lst -> (0..<lst.size()/2).collectEntries{ lst[it*2..it*2+1] } }
toMap(list).collect{ k, v ->
v = nums.collect{ it % k == 0 ? v : '' }
}.transpose()*.join().eachWithIndex{ it, idx ->
println(it ? it : idx+nums.from)
}
}
fizzBuzzN(1..100, [3, 'Fizz', 5, 'Buzz', 7, 'Hoge'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment