Partition an integer x into n primes: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: Specified one import)
m (→‎{{header|Haskell}}: (minor reductions – fractionally faster))
Line 624: Line 624:
[ x
[ x
| x `elem` ps_ ]
| x `elem` ps_ ]
go ps_ x n =
go ps_ x n = ((flip bool [] . head) <*> null) (foldMap found ps_)
let found = foldMap partitionsFound ps_
in bool (head found) [] (null found)
where
where
partitionsFound p =
found p =
let r = x - p
((flip bool [] . return . (p :)) <*> null)
rs = go (delete p (takeWhile (<= r) ps_)) r (n - 1)
((go =<< delete p . flip takeWhile ps_ . (>=)) (x - p) (pred n))
in bool [p : rs] [] (null rs)


-------------------------- TEST ---------------------------
-------------------------- TEST ---------------------------