Anti-primes: Difference between revisions

Content deleted Content added
m OEIS link
Hout (talk | contribs)
→‎{{header|Haskell}}: hlint, hindent. Specified imports, added type signatures.
Line 549:
 
=={{header|Haskell}}==
<lang haskell>import Data.List (find, group)
import Data.Maybe (fromJust)
 
firstPrimeFactor n:: = head $ filter (\xInt -> n `mod` x == 0 ) [2..n]Int
firstPrimeFactor n = head $ filter ((0 ==) . mod n) [2 .. n]
 
allPrimeFactors :: Int -> [Int]
allPrimeFactors 1 = []
allPrimeFactors n = first:(allPrimeFactors(n `div` first))
wherelet first = firstPrimeFactor n
in first : allPrimeFactors (n `div` first)
 
factorCount :: Int -> Int
factorCount 1 = 1
factorCount n = foldr1product (*) (mapsucc (+1. length) <$> map lengthgroup (group $ allPrimeFactors n))
 
divisorCount n:: =Int -> (nInt, factorCount nInt)
divisorCount = (,) <*> factorCount
 
hcnNext :: (Int, Int) -> (Int, Int)
hcnNext (num, factors) = fromJust (find (\x -> snd x > factors) (map divisorCount [num..]))
hcnNext (num, factors) =
fromJust $ find ((> factors) . snd) (divisorCount <$> [num ..])
 
hcnSequence =:: map (fst) $ iterate hcnNext (1, 1)[Int]
hcnSequence = fst <$> iterate hcnNext (1, 1)
 
main :: IO ()
main = putStrLn $ showprint $ take 20 hcnSequence</lang>
{{output}}
<pre>