Self-describing numbers: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: hlint, hindent – minor tidying) |
(→{{header|Haskell}}: Minor consolidation of output into single pruned list) |
||
Line 816:
-- a base-n number are represented as a list of ints, one per digit
allBaseNNumsOfLength :: Int -> [[Int]]
allBaseNNumsOfLength
isSelfDescribing :: [Int] -> Bool
isSelfDescribing num = all (\(i, x) -> x == count i num) $ zip [0 ..] num
-- translate it back into an integer in base-10
Line 826 ⟶ 825:
decimalize = read . map intToDigit
main
main =
print . map decimalize . filter isSelfDescribing . allBaseNNumsOfLength</lang>▼
(print . concat) $
=={{header|Icon}} and {{header|Unicon}}==
|