Skip to content

Instantly share code, notes, and snippets.

@nephilim
Created May 19, 2013 02:36
Show Gist options
  • Save nephilim/621a17edbfb00aff8e5c to your computer and use it in GitHub Desktop.
Save nephilim/621a17edbfb00aff8e5c to your computer and use it in GitHub Desktop.
Project Euler 06
def sum(to:Int) = {
List.range(1, to + 1).sum
} //> sum: (to: Int)Int
def sumSquares(to:Int) = {
to * (to +1) * ( 2 * to + 1 ) / 6
} //> sumSquares: (to: Int)Int
sum(10) //> res1: Int = 55
sumSquares(10) //> res2: Int = 385
math.pow(sum(100), 2).toInt - sumSquares(100) //> res3: Int = 25164150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment