Skip to content

Instantly share code, notes, and snippets.

@non
Created August 30, 2013 15:26
Show Gist options
  • Select an option

  • Save non/6391010 to your computer and use it in GitHub Desktop.

Select an option

Save non/6391010 to your computer and use it in GitHub Desktop.
This is the solution to a useless interview problem.
// fizzbuzz in 116 chars
(1 to 100)map{n=>val v=Seq(3->"fizz",5->"buzz").collect{case(m,s)if n%m==0=>s}.mkString;if(v=="")n.toString else v}
// less cryptic version
val mods = Seq(3 -> "fizz", 5 -> "buzz")
(1 to 100).map { n =>
val words = mods.collect {
case (m, s) if n % m == 0 => s
}
val v = words.mkString()
if (v == "") n.toString else v
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment