Humble numbers: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: Used Applicative in lieu of Control.Arrow)
Line 816: Line 816:
=={{header|Haskell}}==
=={{header|Haskell}}==
<lang haskell>import Data.Set (deleteFindMin, fromList, union)
<lang haskell>import Data.Set (deleteFindMin, fromList, union)
import Control.Arrow ((&&&))
import Data.List (group)
import Data.List (group)
import Data.Bool (bool)
import Data.Bool (bool)
Line 822: Line 821:
----------------------HUMBLE NUMBERS-----------------------
----------------------HUMBLE NUMBERS-----------------------
humbles :: [Integer]
humbles :: [Integer]
humbles =
humbles = go $ fromList [1]
where
let go sofar = x : go (union pruned $ fromList ((x *) <$> [2, 3, 5, 7]))
go sofar = x : go (union pruned $ fromList ((x *) <$> [2, 3, 5, 7]))
where
where
(x, pruned) = deleteFindMin sofar
(x, pruned) = deleteFindMin sofar
in go $ fromList [1]


-- humbles = filter (all (< 8) . primeFactors) [1 ..]
-- humbles = filter (all (< 8) . primeFactors) [1 ..]
Line 834: Line 833:
putStrLn "First 50 Humble numbers:"
putStrLn "First 50 Humble numbers:"
mapM_ (putStrLn . concat) $
mapM_ (putStrLn . concat) $
chunksOf 10 $ (justifyRight 4 ' ' . show) <$> take 50 humbles
chunksOf 10 $ justifyRight 4 ' ' . show <$> take 50 humbles
putStrLn "\nCount of humble numbers for each digit length 1-25:"
putStrLn "\nCount of humble numbers for each digit length 1-25:"
mapM_ print $
mapM_ print $
take 25 $ (head &&& length) <$> group ((length . show) <$> humbles)
take 25 $ ((,) . head <*> length) <$> group (length . show <$> humbles)


--------------------------DISPLAY--------------------------
--------------------------DISPLAY--------------------------