First commit of partial RosettaCode contents.

Pushing this for testing purposes. Lots of work still needed.
This commit is contained in:
Ingy döt Net 2013-04-08 13:02:41 -07:00
commit 1e05ecd7ee
781 changed files with 9080 additions and 0 deletions

View file

@ -0,0 +1,6 @@
(1 to 100) map ( x => (x % 3, x % 5) match{
case (0,0) => "FizzBuzz"
case (0,_) => "Fizz"
case (_,0) => "Buzz"
case _ => x
}) foreach println

View file

@ -0,0 +1,8 @@
def replaceMultiples(x: Int, rs: (Int, String)*) =
rs map {case (n, s) => Either cond (x % n == 0, s, x)} reduceLeft ((a, b) =>
a fold ((_ => b), (s => b fold ((_ => a), (t => Right(s + t))))))
def fizzbuzz(n: Int) =
replaceMultiples(n, 3 -> "Fizz", 5 -> "Buzz") fold ((_ toString), identity)
1 to 100 map fizzbuzz foreach println

View file

@ -0,0 +1,2 @@
def f(a:Int,b:Int,c:String, d:String):String = if(a % b == 0) c else d
for(i <- 1 to 100) println(f(i,15,"FizzBuzz", f(i,3,"Fizz", f(i,5,"Buzz", i.toString))))

View file

@ -0,0 +1,6 @@
(1 to 100) foreach {
case x if (x % 15 == 0) => println("FizzBuzz")
case x if (x % 3 == 0) => println("Fizz")
case x if (x % 5 == 0) => println("Buzz")
case x => println(x)
}