module Euler.Util.Pandigital
( pandigitals
, pandigitalsRev
, pandigitalsRevOfLength
) where
import Euler.Prelude
import Euler.Util.Digit (unDigits)
import qualified Data.List as List
pandigitals :: Integral a => [a]
pandigitals =
permutations [0 .. 9 :: Integer] >>= \p ->
guard (List.head p /= 0) $>
unDigits 10 p
pandigitalsRev :: Integral a => [a]
pandigitalsRev =
foldMap pandigitalsRevOfLength [9, 8 .. (1 :: Int)]
pandigitalsRevOfLength :: (Integral a, Integral b) => a -> [b]
pandigitalsRevOfLength n =
fmap (unDigits 10) . List.reverse . sort . permutations . fmap fromIntegral $
[n, n-1 .. 1]