Created
January 20, 2013 07:09
-
-
Save zerosum/4577094 to your computer and use it in GitHub Desktop.
Project Euler: Problem 6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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