Created
August 30, 2013 15:26
-
-
Save non/6391010 to your computer and use it in GitHub Desktop.
This is the solution to a useless interview problem.
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
| // 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