Skip to content

Instantly share code, notes, and snippets.

@daiksy
Created March 31, 2012 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daiksy/2258828 to your computer and use it in GitHub Desktop.
Save daiksy/2258828 to your computer and use it in GitHub Desktop.
素振り:scalaでfizzbuzz
/** map **/
1 to 100 map {
case i if i % 15 == 0 => "fizzbuzz"
case i if i % 3 == 0 => "fizz"
case i if i % 5 == 0 => "buzz"
case i => i
} foreach println
/** for **/
for(i <- 1 to 100) println(
if (i % 15 == 0) "fizzbuzz"
else if (i % 3 == 0) "fizz"
else if (i % 5 == 0) "buzz"
else i
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment