Skip to content

Instantly share code, notes, and snippets.

@ara-ta3
Created August 24, 2014 10:31
Show Gist options
  • Save ara-ta3/041b7fd799dc6df2a17f to your computer and use it in GitHub Desktop.
Save ara-ta3/041b7fd799dc6df2a17f to your computer and use it in GitHub Desktop.
scalaでfizzbuzz問題
package com.main
object Fizzbuzz {
def main(args:Array[String]){
this.run(15).zipWithIndex foreach {
case(x,i) => println( (i+1) + " : " + x)
}
}
def run(max:Int):Seq[String] = {
var ret:Seq[String] = Seq.range(1,max+1).map{
n => if(n%15 == 0) "fizzbuzz"
else if(n%3 == 0) "fizz"
else if(n%5 == 0) "buzz"
else n.toString()
}
ret
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment