Skip to content

Commit

Permalink
Add code to find self describing numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
bxt committed Jan 12, 2016
1 parent fcb346c commit 2ea8a57
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions unilectures.hs/selfDescribing.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Data.List
import Control.Monad (ap)

isSelfDescribing n = sn == desc sn
where desc = concatMap (show . pred . length) . group . sort . (['0'..to] ++)
to = head $ show $ pred $ length sn
sn = show n

selfDescribing = filter isSelfDescribing [1 ..]

main = print selfDescribing

0 comments on commit 2ea8a57

Please sign in to comment.