Proper divisors: Difference between revisions
→{{header|Haskell}}: Reverted an over-simplification
m (→Python: Functional: Adjusted a couple of names for legibility) |
(→{{header|Haskell}}: Reverted an over-simplification) |
||
Line 2,086:
import Data.List (group, maximumBy, sort)
import Data.Ord (comparing)
import Control.Arrow ((&&&))
properDivisors :: Int -> [Int]
properDivisors x =
foldr
) [1] . group . primeFactors▼
(\(i, e) a -> (*) <$> a <*> scanl (const . (i *)) 1 [1 .. e])
[1]
---------------------------TEST----------------------------
main :: IO ()
main = do
Line 2,109 ⟶ 2,111:
maximumBy (comparing snd) $
(,) <*> (length . properDivisors) <$> [1 .. 20000]
--------------------------DISPLAY--------------------------
fTable :: String -> (a -> String) -> (b -> String) -> (a -> b) -> [a] -> String
fTable s xShow fxShow f xs =
Line 2,117 ⟶ 2,118:
w = maximum (length . xShow <$> xs)
in unlines $
s
{{Out}}
<pre>Proper divisors of [1..10]:
|