Home

# PureScript solution to Project Euler problem 32

`2020-May-12 19:27`

Problem details at Project Euler problem 32 page.

## Test

 12345678910111213 `module` `Euler032Test (euler32suite) ``where` `import` `Prelude` `import` `Euler032 (euler32)``import` `Test``.``Unit (TestSuite, suite, test)``import` `Test``.``Unit``.``Assert ``as` `Assert` `euler32suite ``::` `TestSuite``euler32suite ``=``  ``suite ``"Euler 32"` `do``    ``test ``"Real"` `do``      ``Assert``.``equal ``45228` `(euler32 unit)`

## Solution

 12345678910111213141516171819202122232425262728293031323334353637383940414243 `module` `Euler032 ``where` `import` `Prelude` `import` `Data``.``Array` `as` `A``import` `Data``.``Foldable (``sum``)``import` `Data``.``Set (Set)``import` `Data``.``Set ``as` `S` `dall ``::` `Array` `Int``dall ``=` `A``.``range ``1` `9` `digits ``::` `Int` `-``> ``Array` `Int``digits j``  ``|` `j < ``1`     `=` `[]``  ``|` `otherwise` `=` `digits (j ``/` `10``) `A``.``snoc` (j ```mod`` `10``)` `pandigital ``::` `Int` `-``> ``Int` `-``> ``Int` `-``> Boolean``pandigital j k l ``=``  ``let` `dj ``=` `digits j``      ``dk ``=` `digits k``      ``dl ``=` `digits l``  ``in``    ``(A``.``length` `dj ``+` `A``.``length` `dk ``+` `A``.``length` `dl) ``==` `9``    ``&& A``.``sort (A``.``concat` `[dj, dk, dl]) ``==` `dall` `pdone ``::` `Int` `-``> ``Int` `-``> ``Int` `-``> ``Int` `-``> ``Int` `-``> Set ``Int` `-``> Set ``Int``pdone j jg kf kg k s``  ``|` `j > jg    ``=` `s``  ``|` `k > kg    ``=` `pdone (j ``+` `1``) jg kf kg kf s``  ``|` `otherwise` `=``      ``let` `f ``=` `j ``*` `k``          ``g ``=` `pandigital j k f``          ``d ``=` `if` `g ``then` `S``.``insert f s ``else` `s``      ``in` `pdone j jg kf kg (k ``+` `1``) d` `pandigitals ``::` `Unit ``-``> Set ``Int``pandigitals ``_` `=``  ``S``.``union (pdone ``1` `9` `1234` `9876` `1234` `S``.``empty)``          ``(pdone ``12` `98` `123` `987` `123` `S``.``empty)` `euler32 ``::` `Unit ``-``> ``Int``euler32 ``_` `=` `sum` `\$` `pandigitals unit`