Partition an integer x into n primes: Difference between revisions
Content added Content deleted
Line 1,371: | Line 1,371: | ||
</pre> |
</pre> |
||
=={{header|Mathematica}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
⚫ | |||
<lang Mathematica> |
|||
⚫ | |||
PrimeList[count_] := Prime/@Range[count];(*Just a helper to create an initial list of primes of the desired length*) |
PrimeList[count_] := Prime/@Range[count];(*Just a helper to create an initial list of primes of the desired length*) |
||
AppendPrime[list_] := Append[list,NextPrimeMemo[Last@list]];(*Another helper that makes creating the next candidate less verbose*) |
AppendPrime[list_] := Append[list,NextPrimeMemo[Last@list]];(*Another helper that makes creating the next candidate less verbose*) |
||
Line 1,416: | Line 1,412: | ||
TimedResults = ReleaseHold[Hold[AbsoluteTiming[FormatResult[PrimePartition @@ #, Last@#]]] & /@TestCases](*I thought it would be interesting to include the timings, which are in seconds*) |
TimedResults = ReleaseHold[Hold[AbsoluteTiming[FormatResult[PrimePartition @@ #, Last@#]]] & /@TestCases](*I thought it would be interesting to include the timings, which are in seconds*) |
||
TimedResults // TableForm |
TimedResults // TableForm</lang> |
||
</lang> |
|||
{{out}} |
{{out}} |
||
⚫ | |||
<pre> |
|||
⚫ | |||
0.000407 Partitioned 18 with 2 primes: 5+13 |
0.000407 Partitioned 18 with 2 primes: 5+13 |
||
0.000346 Partitioned 19 with 3 primes: 3+5+11 |
0.000346 Partitioned 19 with 3 primes: 3+5+11 |
||
Line 1,431: | Line 1,425: | ||
20.207 Partitioned 22699 with 3 primes: 3+5+22691 |
20.207 Partitioned 22699 with 3 primes: 3+5+22691 |
||
0.357536 Partitioned 22699 with 4 primes: 2+3+43+22651 |
0.357536 Partitioned 22699 with 4 primes: 2+3+43+22651 |
||
57.9928 Partitioned 40355 with 3 primes: 3+139+40213 |
57.9928 Partitioned 40355 with 3 primes: 3+139+40213</pre> |
||
</pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |