Skip to main content
Best answer by StuartBruff

Neat. I was bored at lunchtime, so I thought I'd generalize things a little bit generate arbitrary k-tuples (defined by the required difference between the first member of the k-tuple and the other members).

Stuart

5 replies

Werner_E
25-Diamond I
March 17, 2014

Use the output of PrimeTriplet as input. Run from the second to the last but one element and remove every triple where one of its numbers are included in the next triple. A function overlap(triple1, triple2) may be useful in doing so.

Alternative approach: lookup the prime before the first and the prime after the last element of your triple. If the difference of any of them to the center element of the triple is 6, discard it.

23-Emerald V
March 17, 2014

As the triplet selection algorithm already sorts the triplets in ascending order, it should be sufficient to just ensure that:

the first number in a triplet is greater then the last in the previous triplet

and

the last number in a triplet is less than the first number in the succeding triplet

Stuart

Werner_E
25-Diamond I
March 18, 2014

Oh, yes! That sure was too obvious and too easy for me too see

In the attached sheet I nevertheless had to resort to my alternative approach as I don't use the precalculated triples.

P1.png

The routines are written so that the argument is either a scalar (highes prime number involved) or, as in Liu's routine, a vector of primes.

So if you want to collect all routines in one programm as in the original sheet, you would calculate the prime list only once.

P2.png