這一題要找前 100 個自然數和的平方和平方和的差值

https://projecteuler.net/problem=6

我是直接寫程式來解的,就照著做而已

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{-# OPTIONS_GHC -Wall #-}

square :: Int -> Int
square x = x * x

p6 :: Int
p6 = let xs = [1..100] in abs $ sum (map square xs)
                                 - square (sum xs)

main :: IO()
main = do
    print $ p6