cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Extract Non-overlap Triplets

lvl107
18-Opal

How to Extract Non-overlap Triplets

Hello, Everyone.

Extract_Non_Overlap_Triplet+.PNG

( or Refer : http://communities.ptc.com/message/154874#154874 )

Thanks in advance for your time and help.

Best Regards.

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

5 REPLIES 5
Werner_E
24-Ruby IV
(To:lvl107)

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.

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

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

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

View solution in original post

Great work.

What shall I say - welcome back!

Your primes2() is twice as fast as the routine listPrimes() in my sheet and uses up less ressources - great!

Announcements
Check out the latest
Mathcad Tip
"PTC Mathcad 15 / Prime 1-6 Update."