Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
33
Task/Prime-triangle/Mathematica/prime-triangle.math
Normal file
33
Task/Prime-triangle/Mathematica/prime-triangle.math
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
ClearAll[FindPrimeTriangles, FindPrimeTrianglesHelper]
|
||||
FindPrimeTriangles[max_] :=
|
||||
Module[{count = 0, firstsolution, primes, primeQ},
|
||||
primes = PrimeQ[Range[2 max]];
|
||||
primeQ[n_] := primes[[n]];
|
||||
ClearAll[FindPrimeTrianglesHelper];
|
||||
FindPrimeTrianglesHelper[start_, remainder_, mxx_] :=
|
||||
Module[{last, nexts, r, newstart, newremainder},
|
||||
If[Length[remainder] > 0,
|
||||
last = Last[start];
|
||||
Do[
|
||||
r = remainder[[ri]];
|
||||
If[primeQ[last + r],
|
||||
newstart = Append[start, r];
|
||||
newremainder = Delete[remainder, ri];
|
||||
FindPrimeTrianglesHelper[newstart, newremainder, mxx]
|
||||
]
|
||||
,
|
||||
{ri, Length[remainder]}
|
||||
]
|
||||
,
|
||||
If[primeQ[Last[start] + mxx],
|
||||
count++;
|
||||
If[count == 1,
|
||||
Print[Append[start, mxx]]
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
FindPrimeTrianglesHelper[{1}, Range[2, max - 1], max];
|
||||
count
|
||||
]
|
||||
Table[FindPrimeTriangles[S],{S, 2, 20}]
|
||||
Loading…
Add table
Add a link
Reference in a new issue