Home

# PureScript solution to Project Euler problem 28

`2020-Jan-26 12:12`

Problem details at Project Euler problem 28 page.

## Test

 123456789101112131415 `module` `Euler028Test (euler28suite) ``where` `import` `Prelude` `import` `Euler028 (euler28)``import` `Test``.``Unit (TestSuite, suite, test)``import` `Test``.``Unit``.``Assert ``as` `Assert` `euler28suite ``::` `TestSuite``euler28suite ``=``  ``suite ``"Euler 28"` `do``    ``test ``"Warmup"` `do``      ``Assert``.``equal ``101` `(euler28 ``5``)``    ``test ``"Real"` `do``      ``Assert``.``equal ``669171001` `(euler28 ``1001``)`

## Solution

 123456789101112131415161718 `module` `Euler028 ``where` `import` `Prelude` `import` `Data``.``Array` `(range)``import` `Data``.``Foldable (``sum``)` `corners ``::` `Int` `-``> ``Array` `Int``corners n``  ``|` `n ``==` `1`    `=` `[``1``]``  ``|` `otherwise` `=``      ``let` `j ``=` `1` `+` `(n ``-` `1``) ``*` `2``          ``k ``=` `j ``*` `j ``          ``f l ``=` `k ``-` `l ``*` `(j ``-` `1``)``      ``in` `map` `f (range ``0` `3``)` `euler28 ``::` `Int` `-``> ``Int``euler28 n ``=` `sum` `\$` `join ``\$` `map` `corners ``\$` `range ``1` `(n ``/` `2` `+` `1``)`