Product of min and max prime factors: Difference between revisions
Product of min and max prime factors (view source)
Revision as of 05:43, 1 November 2022
, 1 year ago→{{header|Haskell}}: Tidied
m (→{{header|AppleScript}}: Dedicated primeFactors handler. Multiplications moved to task code.) |
m (→{{header|Haskell}}: Tidied) |
||
Line 734:
=={{header|Haskell}}==
<syntaxhighlight lang=haskell>import Data.List
import Data.List.Split (chunksOf)
import Data.Numbers.Primes (primeFactors)
import Text.Printf (printf)
----------- PRODUCT OF MIN AND MAX PRIME FACTORS ---------
f = ((*) . head <*> last) . primeFactors
--------------------------- TEST -------------------------
main :: IO ()
main =
putStrLn $
1 : (f <$> [2 ..])
------------------------- DISPLAY ------------------------
table :: String -> [[String]] -> String
table gap rows =
let ws = maximum . fmap length <$> transpose rows
pw = printf . flip intercalate ["%", "s"] . show
in unlines $ intercalate gap . zipWith pw ws <$> rows</syntaxhighlight>
{{Out}}
<pre>
=={{header|J}}==
|