Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Anti-primes/Haskell/anti-primes.hs
Normal file
28
Task/Anti-primes/Haskell/anti-primes.hs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import Data.List (find, group)
|
||||
import Data.Maybe (fromJust)
|
||||
|
||||
firstPrimeFactor :: Int -> Int
|
||||
firstPrimeFactor n = head $ filter ((0 ==) . mod n) [2 .. n]
|
||||
|
||||
allPrimeFactors :: Int -> [Int]
|
||||
allPrimeFactors 1 = []
|
||||
allPrimeFactors n =
|
||||
let first = firstPrimeFactor n
|
||||
in first : allPrimeFactors (n `div` first)
|
||||
|
||||
factorCount :: Int -> Int
|
||||
factorCount 1 = 1
|
||||
factorCount n = product ((succ . length) <$> group (allPrimeFactors n))
|
||||
|
||||
divisorCount :: Int -> (Int, Int)
|
||||
divisorCount = (,) <*> factorCount
|
||||
|
||||
hcnNext :: (Int, Int) -> (Int, Int)
|
||||
hcnNext (num, factors) =
|
||||
fromJust $ find ((> factors) . snd) (divisorCount <$> [num ..])
|
||||
|
||||
hcnSequence :: [Int]
|
||||
hcnSequence = fst <$> iterate hcnNext (1, 1)
|
||||
|
||||
main :: IO ()
|
||||
main = print $ take 20 hcnSequence
|
||||
Loading…
Add table
Add a link
Reference in a new issue