Anonymous user
Partition an integer x into n primes: Difference between revisions
Partition an integer x into n primes (view source)
Revision as of 23:06, 27 April 2020
, 4 years ago→{{header|Mathematica}}
m (→{{header|Phix}}: is_prime() now builtin) |
|||
Line 1,075:
=={{header|Mathematica}}==
This can be done with IntegerPartitions:
<lang Mathematica>partition[x_,n_]:= "Partitioned "<>ToString[x]<>" with "<>ToString[n]<>" primes: "<>StringRiffle[
,"+"]
partition[18, 2]
partition[19, 3]
Print["Partitioned ", x, " with ", n, " primes: ", ▼
▲ Sort[Select[IntegerPartitions[x, {n}, Prime@Range@PrimePi@x],
▲F[40355, 3]</lang>
{{out}}
<pre>
Partitioned
Partitioned 20 with 4 primes: impossible
</pre>
|