Largest proper divisor of n: Difference between revisions

Content added Content deleted
(→‎{{header|Raku}}: demonstrate for some larger numbers too)
Line 290: Line 290:
| 1 < length ab = quot n (last ab)
| 1 < length ab = quot n (last ab)
| otherwise = 1
| otherwise = 1
where
where
root = (floor . sqrt) (fromIntegral n :: Double)
root = (floor . sqrt) (fromIntegral n :: Double)
ab = take 2 $ [1 .. root] >>= (\x -> [x | 0 == rem n x])
ab = take 2 [x | x <- [1 .. root], 0 == rem n x]

main :: IO ()
main :: IO ()
main =
main =
(putStr . unlines . map concat . chunksOf 10) $
(putStr . unlines . map concat . chunksOf 10) $
printf "%3d" . maxProperDivisors <$> [1 .. 100]</lang>
printf "%3d" . maxProperDivisors <$> [1 .. 100]</lang>


<pre> 1 1 1 2 1 3 1 4 3 5
<pre> 1 1 1 2 1 3 1 4 3 5