Created
August 17, 2011 08:10
-
-
Save fumokmm/1151077 to your computer and use it in GitHub Desktop.
お題:FizzBuzz(Nパターン) solved by Groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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