Jump to content

Partition an integer x into n primes: Difference between revisions

m
Line 1,371:
</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<lang Mathematica>NextPrimeMemo[n_] := (NextPrimeMemo[n] = NextPrime[n]);(*This improves performance by 30% or so*)
 
<lang Mathematica>
NextPrimeMemo[n_] := (NextPrimeMemo[n] = NextPrime[n]);(*This improves performance by 30% or so*)
 
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*)
 
Line 1,416 ⟶ 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 // TableForm</lang>
</lang>
 
 
{{out}}
<pre>0.111699 Partitioned 99809 with 1 prime: 99809
<pre>
0.111699 Partitioned 99809 with 1 prime: 99809
0.000407 Partitioned 18 with 2 primes: 5+13
0.000346 Partitioned 19 with 3 primes: 3+5+11
Line 1,431 ⟶ 1,425:
20.207 Partitioned 22699 with 3 primes: 3+5+22691
0.357536 Partitioned 22699 with 4 primes: 2+3+43+22651
57.9928 Partitioned 40355 with 3 primes: 3+139+40213</pre>
</pre>
 
=={{header|Nim}}==
1,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.