Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions
Content added Content deleted
Line 299: | Line 299: | ||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
<lang haskell>import |
<lang haskell>import Text.Printf (printf) |
||
import Text.Printf (printf) |
|||
import Control.Monad (guard) |
import Control.Monad (guard) |
||
Line 306: | Line 305: | ||
sequence_A069654 = go 1 nDivCount |
sequence_A069654 = go 1 nDivCount |
||
where |
where |
||
nDivCount = (,) <*> length |
nDivCount = (,) <*> length . divisors <$> [1..] |
||
divisors n = [1.. |
divisors n = [1..floor (sqrt $ realToFrac n)] >>= \x -> do |
||
guard (n `mod` x == 0) |
|||
let y = n `div` x |
|||
if x == y then [x] else [x,y] |
|||
go t ((n,d):xs) |
go t ((n,d):xs) |
||
| d == t = (t,n):go (succ t) xs |
| d == t = (t,n):go (succ t) xs |