1
0
Fork 0
mirror of https://github.com/correl/elm.git synced 2024-12-22 03:00:07 +00:00
elm/exercises/difference-of-squares/DifferenceOfSquares.example.elm
2016-12-17 17:29:40 -05:00

20 lines
336 B
Elm

module DifferenceOfSquares exposing (..)
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) (List.range 0 n))
difference : Int -> Int
difference n =
squareOfSum n - sumOfSquares n