Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// http://d.hatena.ne.jp/fumokmm/20110815/1313405510
def fizzBuzz(List<Integer> nums, Map<Integer, String> dict) {
nums.each { int n ->
println dict.findAll{ n % it.key == 0 }.collect{ dict[it.key] }.join() ?: n
}
}
def convertDict(List dict) {
assert dict.size() % 2 == 0
(0..<dict.size()).step(2).collectEntries{ [dict[it], dict[++it]] }
}
fizzBuzz(1..100, convertDict([3, "Fizz", 5, "Buzz", 7, "Hoge"]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment