-
-
Save miracle0k/8e214f6597a97b745d31 to your computer and use it in GitHub Desktop.
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
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