Help us understand the problem. What is going on with this article?

Project EulerをHaskellで解いていく(Problem6: Sum square difference)

More than 1 year has passed since last update.

問題文

The sum of the squares of the first ten natural numbers is,

``` 1^2+2^2+3^2+...+10^2 = 385
```

The square of the sum of the first ten natural numbers is,

``` (1+2+3...+10)^2 = 3025
```

Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.

``` 1^2+2^2+3^2+...+10^2 = 385
```

``` (1+2+3...+10)^2 = 3025
```

これらの数の差は 3025 - 385 = 2640 となる.

コード

```main::IO()
main = do
let x1 = sum \$ map (^2) [1..100]
let x2 = sum [1..100] ^ 2
print \$ x2 - x1
```

```func1::[Int] -> Int
func1 = sum . map (^2)

func2::[Int] -> Int
func2 = (^2) . sum

func3::[Int] -> Int
func3 = foldr (-) 0 . (\x -> map (\f -> f x) [func2, func1])

main::IO()
main = do
print \$ func3 [1..100]
```
プログラム書けないマン
https://ksk.netlify.app
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away