Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions
Content added Content deleted
Line 301: | Line 301: | ||
<lang haskell>import Data.List (nub) |
<lang haskell>import Data.List (nub) |
||
import Text.Printf (printf) |
import Text.Printf (printf) |
||
import Control.Monad (guard) |
|||
sequence_A069654 :: [(Int,Int)] |
sequence_A069654 :: [(Int,Int)] |
||
Line 306: | Line 307: | ||
where |
where |
||
nDivCount = (,) <*> divisorCount <$> [1..] |
nDivCount = (,) <*> divisorCount <$> [1..] |
||
divisorCount = length . nub |
divisorCount = length . nub . divisors |
||
where |
where |
||
divisors n = [ ( |
divisors n = [1..ceiling (sqrt $ realToFrac n)] >>= \x -> |
||
guard (n `mod` x == 0) >> [x, n `div` x] |
|||
, n `mod` x == 0 ] |
|||
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 |