Narcissistic decimal number: Difference between revisions

Content added Content deleted
(→‎Haskell - Reduced search: (used unfoldr for digitList))
(→‎Haskell reduced search: (used swap in digitList))
Line 1,314: Line 1,314:


<lang haskell>import Data.List (sort, unfoldr)
<lang haskell>import Data.List (sort, unfoldr)
import Data.Tuple (swap)


narcissiOfLength :: Int -> [Int]
narcissiOfLength :: Int -> [Int]
Line 1,328: Line 1,329:
(\x ->
(\x ->
if x > 0
if x > 0
then let (q, r) = quotRem x 10
then Just (swap (quotRem x 10))
in Just (r, q)
else Nothing)
else Nothing)