Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1 +1 @@
|
|||
for (n <- 1 to 100) println(List((15, "FizzBuzz"), (3, "Fizz"), (5, "Buzz")).find(t => n % t._1 == 0).getOrElse((0, n.toString))._2)
|
||||
for (i <- 1 to 100) println(Seq(15 -> "FizzBuzz", 3 -> "Fizz", 5 -> "Buzz").find(i % _._1 == 0).map(_._2).getOrElse(i))
|
||||
|
|
|
|||
5
Task/FizzBuzz/Scala/fizzbuzz-5.scala
Normal file
5
Task/FizzBuzz/Scala/fizzbuzz-5.scala
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def fizzbuzz(l: List[String], n: Int, s: String) = if (l.head.toInt % n == 0) l :+ s else l
|
||||
def fizz(l: List[String]) = fizzbuzz(l, 3, "Fizz")
|
||||
def buzz(l: List[String]) = fizzbuzz(l, 5, "Buzz")
|
||||
def headOrTail(l: List[String]) = if (l.tail.size == 0) l.head else l.tail.mkString
|
||||
Stream.from(1).take(100).map(n => List(n.toString)).map(fizz).map(buzz).map(headOrTail).foreach(println)
|
||||
Loading…
Add table
Add a link
Reference in a new issue