Jump to content

Sequence: smallest number greater than previous term with exactly n divisors: Difference between revisions

m
(added Haskell)
Line 301:
<lang haskell>import Data.List (nub)
import Text.Printf (printf)
 
divisorCount :: Int -> Int
divisorCount = length . nub . foldr (\(a, b) r -> a:b:r) [] . divisors
where
divisors n = [(x, n `div` x) | x <- [1..ceiling (sqrt $ realToFrac n)], n `mod` x == 0]
 
sequence_A069654 :: [(Int,Int)]
Line 311 ⟶ 306:
where
nDivCount = (,) <*> divisorCount <$> [1..]
divisorCount = length . nub . foldr (\(a, b) r -> a:b:r) [] . divisors
where
divisors n = [(x, n `div` x)
divisors n = [(x, n `div` x) | x <- [1..ceiling (sqrt $ realToFrac n)], n `mod` x == 0]
, n `mod` x == 0]
go t ((n,d):xs)
| d == t = (d,n) : go (succ t) xs
Line 334:
a(15)= 4624
</pre>
 
=={{header|J}}==
<lang j>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.