uhlenheuerdotnet
programming, .NET, linux and others

Scala: Project Euler problem 6

by Gregor Uhlenheuer on July 17, 2012

I guess I am rolling - here goes problem number 6:

class Euler006 extends Euler {

  def number = 6

  def solution = {

    def sumOfSquares(n : Int) = {
      Stream.range(1, n+1, 1).map(x => x * x).sum
    }

    def squareOfSums(n : Int) = {
      val sums = Stream.range(1, n+1, 1).sum
      sums * sums
    }

    squareOfSums(100) - sumOfSquares(100)
  }
}

This one contains nothing too special at all. In fact I am not too sure if there is any real benefit in using Stream.range instead of Range.

This post is tagged with euler, scala and programming