Proper divisors: Difference between revisions
→{{header|Haskell}}: Corrected the reduced definition in terms of primeFactors
(→{{header|Haskell}}: Reverted an over-simplification) |
(→{{header|Haskell}}: Corrected the reduced definition in terms of primeFactors) |
||
Line 2,086:
import Data.List (group, maximumBy, sort)
import Data.Ord (comparing)
properDivisors :: Int -> [Int]
properDivisors
flip ((<*>) . fmap (*)) . scanl (*) 1
) [1] . group . primeFactors
---------------------------TEST----------------------------
main :: IO ()
Line 2,111 ⟶ 2,108:
maximumBy (comparing snd) $
(,) <*> (length . properDivisors) <$> [1 .. 20000]
--------------------------DISPLAY--------------------------
fTable :: String -> (a -> String) -> (b -> String) -> (a -> b) -> [a] -> String
Line 2,118 ⟶ 2,115:
w = maximum (length . xShow <$> xs)
in unlines $
s
{{Out}}
<pre>Proper divisors of [1..10]:
|