Jump to content

Self-describing numbers: Difference between revisions

→‎{{header|Haskell}}: Minor consolidation of output into single pruned list
(→‎{{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 n = replicateM n<*> (enumFromTo [0 ..n- subtract 1])
 
isSelfDescribing :: [Int] -> Bool
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
Line 826 ⟶ 825:
decimalize = read . map intToDigit
 
main =:: forM_IO [1..7] $()
main =
print . map decimalize . filter isSelfDescribing . allBaseNNumsOfLength</lang>
(print . concat) $
print . map decimalize . filter isSelfDescribing . allBaseNNumsOfLength <$> [1 .. 7]</lang>
 
=={{header|Icon}} and {{header|Unicon}}==
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.