May. 24th, 2016
a decent fizzbuzz
May. 24th, 2016 04:31 pmCan anybody write a really beautiful one?
All I could come up with is this:
UPD from 2024:
All I could come up with is this:
def fizzbuzz(n: Int) = 1 to n foreach { i => def p(k: Int, what: Any, alt: => Unit) = if (i % k == 0) print(what) else alt p(15, "fizzbuzz", p(3, "fizz", p(5, "buzz", p(1, i, {})))); println }
UPD from 2024:
def fizzbuzz(n: Int) = 1 to n foreach { i => def p(k: Int, what: Any, alt: => Any) = if (i % k == 0) what else alt println(p(15, "fizzbuzz", p(3, "fizz", p(5, "buzz", p(1, i, i))))) }