Skip to content
Gregory Morrison edited this page Feb 11, 2023 · 3 revisions

Scala, introduced in 2003, is an object-orientedfunctional language for the JVM. Scala looks like it will be useful and fun to learn, but it seems to have a steep learning curve for me. It took me a whole day to figure out the constructs for even this simple version of Euler1:

// Euler1 in Scala

object euler1 {
    def calc(x: Int): Int = {
        val ints = (1 to x).filter(i => i%3==0 || i%5==0)
        return ints.foldLeft(0) { (total,n) => total+n }
    }

    def main(args: Array[String]) = {
        Console.println( calc(999) )
    }
}

To install Scala on Fedora, simply yum install scala. Scala programs are executed like Java. First compile using the compiler, then run using the runtime:

$ scalac euler1.scl
$ scala -cp . euler1
233168
$
Clone this wiki locally