Skip to content

Instantly share code, notes, and snippets.

@zerosum
Created January 20, 2013 07:09
Show Gist options
  • Save zerosum/4577094 to your computer and use it in GitHub Desktop.
Save zerosum/4577094 to your computer and use it in GitHub Desktop.
Project Euler: Problem 6
object Euler0006 {
def main(args: Array[String]): Unit = {
val range = (1 to 100).toList
println(differenceOfSumSquare(range))
}
private def differenceOfSumSquare(range: List[Int]): Int = {
val sumOfSquare = range.map(Math.pow(_, 2)).sum.toInt
val squareOfSum = Math.pow(range.sum, 2).toInt
squareOfSum - sumOfSquare
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment