Abundant odd numbers: Difference between revisions

m
→‎{{header|Haskell}}: Tidied the Data.Numbers.Primes version – pruned out redundant import.
m (→‎{{header|AppleScript}}: Minor change to aliquotSum() handler.)
m (→‎{{header|Haskell}}: Tidied the Data.Numbers.Primes version – pruned out redundant import.)
Line 2,864:
 
Or, importing Data.Numbers.Primes (and significantly faster):
<lang haskell>import Data.Numbers.PrimesList (group, sort)
import Data.List (group, sort)Numbers.Primes
import Data.Bool (bool)
 
abundantTuple :: Int -> [(Int, Int)]
abundantTuple n =
| n <let x = [(divisorSum n, x)]
in [(n, x) | otherwisen =< [x]
where
x = divisorSum n
 
divisorSum :: Int -> Int
Line 2,882 ⟶ 2,879:
foldr --
(flip ((<*>) . fmap (*)) . scanl (*) 1)
[1] .
group . primeFactorsgroup
. primeFactors
 
main :: IO ()
main = do
putStrLn "First 25 abundant odd numbers with their divisor sums:"
mapM_ print $ take 25 ([1, 3 ..] >>= abundantTuple)
--
putStrLn "\n1000th odd abundant number with its divisor sum:"
print $ ([1, 3 ..] >>= abundantTuple) !! 999
--
putStrLn "\nFirst odd abundant number over 10^9, with its divisor sum:"
let billion = 10 ^ 9 :: Int
print $ head ([1 + billion, 3 + billion ..] >>= abundantTuple)</lang>
{{Out}}
<pre>First 25 abundant odd numbers with their divisor sums:
9,655

edits