Partition an integer x into n primes: Difference between revisions
m
→{{header|Haskell}}: Used Data.Numbers.Primes, tidied.
(Added Prolog Solution) |
m (→{{header|Haskell}}: Used Data.Numbers.Primes, tidied.) |
||
Line 608:
=={{header|Haskell}}==
<lang haskell>
import Data.Numbers.Primes
import Data.List (delete, intercalate)
partition :: Int -> Int -> [Int]
partition x n
| n <= 1 =
[ x
|
| otherwise =
where
ps = takeWhile (<= x) primes
[ x
| x `elem` ps_ ]
let found = foldMap partitionsFound ps_
in
where
partitionsFound p =
let r = x - p
rs =
in
main :: IO ()
main =
mapM_ putStrLn $
(\(x, n) ->
concat
[ [(99809, 1), (18, 2), (19, 3), (20, 4), (2017, 24)]
, (
, [(40355, 3)]
]
justifyLeft :: Int -> Char -> String -> String
justifyLeft n c s = take n (s ++ replicate n c)</lang>
{{Out}}
<pre>(99809,1) -> 99809
|