Product of divisors: Difference between revisions
m
→{{header|Haskell}}: Tidied
m (→{{header|Haskell}}: Tidied) |
|||
Line 589:
------------------------- DIVISORS -----------------------
divisors n =
((<>) <*> (rest . reverse . fmap (quot n))) $
filter ((0 ==) . rem n) [1 .. root]
where
root = (floor . sqrt . fromIntegral) n
Line 602 ⟶ 601:
-------------- SUMS AND PRODUCTS OF DIVISORS -------------
main :: IO ()
main =
mapM_
putStrLn
[ "Sums of divisors of [1..100]:",
]
test :: (Show a, Integral a) => ([a] -> a) -> String▼
▲ => ([a] -> a) -> String
test f =
let xs = show . f . divisors <$> [1 .. 100]
w = maximum $ length <$> xs
in unlines $
in unlines $ unwords <$> fmap (fmap (justifyRight w ' ')) (chunksOf 5 xs)▼
unwords
<$> fmap
(chunksOf 5 xs)
justifyRight :: Int -> Char -> String -> String
|