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: | Line 816: | ||
-- a base-n number are represented as a list of ints, one per digit |
-- a base-n number are represented as a list of ints, one per digit |
||
allBaseNNumsOfLength :: Int -> [[Int]] |
allBaseNNumsOfLength :: Int -> [[Int]] |
||
allBaseNNumsOfLength |
allBaseNNumsOfLength = replicateM <*> (enumFromTo 0 . subtract 1) |
||
isSelfDescribing :: [Int] -> Bool |
isSelfDescribing :: [Int] -> Bool |
||
isSelfDescribing num = |
isSelfDescribing num = all (\(i, x) -> x == count i num) $ zip [0 ..] num |
||
all (\(i,x) -> x == count i num) $ zip [0..] num |
|||
-- translate it back into an integer in base-10 |
-- translate it back into an integer in base-10 |
||
Line 826: | Line 825: | ||
decimalize = read . map intToDigit |
decimalize = read . map intToDigit |
||
main |
main :: IO () |
||
main = |
|||
⚫ | |||
(print . concat) $ |
|||
⚫ | |||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |