Sequence: smallest number with exactly n divisors: Difference between revisions

→‎{{header|Haskell}}: Added a draft in Haskell
(→‎{{header|Haskell}}: Added a draft in Haskell)
Line 307:
[1 2 4 6 16 12 64 24 36 48 1024 60 4096 192 144]
</pre>
 
=={{header|Haskell}}==
Without any subtlety or optimisation, but still fast at this modest scale:
<lang haskell>import Data.Numbers.Primes (primeFactors)
import Data.List (find, group, sort)
import Data.Maybe (catMaybes)
 
a005179 :: [Int]
a005179 =
catMaybes $
(\n -> find (\x -> n == succ (length (properDivisors x))) [1 ..]) <$> [1 ..]
 
properDivisors :: Int -> [Int]
properDivisors =
init .
sort .
foldr --
(flip ((<*>) . fmap (*)) . scanl (*) 1)
[1] .
group . primeFactors
 
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>
 
 
 
=={{header|J}}==
9,655

edits