Narcissistic decimal number: Difference between revisions

Content added Content deleted
(→‎Haskell :: Reduced search: Simpler predicate, digitList domain extended to 0)
Line 2,025: Line 2,025:


narcissiOfLength :: Int -> [Int]
narcissiOfLength :: Int -> [Int]
narcissiOfLength nDigits = snd <$> digitTree nDigits []
narcissiOfLength nDigits = snd <$> go nDigits []
where
where
powers = ((,) <*> (^ nDigits)) <$> [0 .. 9]
powers = ((,) <*> (^ nDigits)) <$> [0 .. 9]
digitTree n parents =
go n parents =
bool
bool
(filter (isDaffodil nDigits . snd) parents)
(filter (isDaffodil nDigits . snd) parents)
(digitTree
(go
(n - 1)
(pred n)
(bool
(bool
(parents >>=
(parents >>=
Line 2,061: Line 2,061:
putStrLn $
putStrLn $
fTable
fTable
"Narcissitic decimal numbers of length 1-7:\n"
"Narcissistic decimal numbers of length 1-7:\n"
show
show
show
show
Line 2,074: Line 2,074:
s : fmap (((++) . rjust w ' ' . xShow) <*> ((" -> " ++) . fxShow . f)) xs</lang>
s : fmap (((++) . rjust w ' ' . xShow) <*> ((" -> " ++) . fxShow . f)) xs</lang>
{{Out}}
{{Out}}
<pre>Narcissitic decimal numbers of length 1-7:
<pre>Narcissistic decimal numbers of length 1-7:


1 -> [0,1,2,3,4,5,6,7,8,9]
1 -> [0,1,2,3,4,5,6,7,8,9]