Sequence: smallest number with exactly n divisors: Difference between revisions
Sequence: smallest number with exactly n divisors (view source)
Revision as of 04:50, 6 April 2022
, 2 years ago→{{header|Haskell}}: Preferred mapMaybe to catMaybes, tidied.
(Added XPL0 example.) |
(→{{header|Haskell}}: Preferred mapMaybe to catMaybes, tidied.) |
||
Line 559:
=={{header|Haskell}}==
Without any subtlety or optimisation, but still fast at this modest scale:
<lang haskell>import Data.
import Data.
import Data.
------------------------- A005179 ------------------------
a005179 :: [Int]
a005179 =
mapMaybe
( \n ->
(\n -> find ((n ==) . succ . length . properDivisors) [1 ..]) <$> [1 ..]▼
find
[1 ..]
)
[1 ..]
--------------------------- TEST -------------------------
main :: IO ()▼
------------------------- GENERIC ------------------------
properDivisors :: Int -> [Int]
properDivisors =
init
. foldr
(flip ((<*>) . fmap (*)) . scanl (*) 1)
[1]
. primeFactors</lang>
▲main :: IO ()
▲main = print $ take 15 a005179</lang>
{{Out}}
<pre>[1,2,4,6,16,12,64,24,36,48,1024,60,4096,192,144]</pre>
|