Skip to content

Instantly share code, notes, and snippets.

@miracle0k
Created May 17, 2013 23:20
Show Gist options
  • Save miracle0k/8e214f6597a97b745d31 to your computer and use it in GitHub Desktop.
Save miracle0k/8e214f6597a97b745d31 to your computer and use it in GitHub Desktop.
package euler
class p006 {
private def sumOfSquare(to: Range): Int = {
val sum = to.foldLeft(0)((x,y) => x + y)
sum * sum
}
private def squareOfSum(to: Range): Int = {
to.foldLeft(0)((x,y) => x + y * y)
}
def run(to: Range): Int = {
sumOfSquare(to) - squareOfSum(to)
}
}
object Run extends App{
println(new p006().run(1 to 100))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment