mirror of
https://github.com/correl/elm.git
synced 2024-12-30 11:01:50 +00:00
20 lines
295 B
Text
20 lines
295 B
Text
|
module DifferenceOfSquares (..) where
|
||
|
|
||
|
|
||
|
squareOfSum : Int -> Int
|
||
|
squareOfSum n =
|
||
|
let
|
||
|
sum = n * (n + 1) // 2
|
||
|
in
|
||
|
sum * sum
|
||
|
|
||
|
|
||
|
sumOfSquares : Int -> Int
|
||
|
sumOfSquares n =
|
||
|
List.sum (List.map (\m -> m * m) [0..n])
|
||
|
|
||
|
|
||
|
difference : Int -> Int
|
||
|
difference n =
|
||
|
squareOfSum n - sumOfSquares n
|