Contribution on Puzzlet #019

From:  Denis Borris []

I come up with 4 additional ones;
you have 13901-21557-28277-55661-68897;
I get those too, also 26681-31247-33617-97367 your "check prime module" faulty ? :)

Here's my program:
100 For n = 10001 to 99967 step 2                  'note 1
110 If n@10 = 5 or n@10 = 3 or n@10 = 9 then 180   'note 2
120 x = n
130 For m = 0 to 10 step 2
140 x = x + m
150 If prmdiv(x) <> x then cancel for : goto 180   'note 3
160 Next m
170 Print n, n+2, n+6, n+12, n+20, n+30            'note 4
180 Next n

How u like dat for compactness, brudder?!
Total loops = 23143: 17997 (n) and 5146 (m).

note 1: high is 99967, since 99967 + 30 = 99997

note 2: last digit can only be 1 or 7:
5 is out, 3 is out (3+2 = 5) and 9 is out (9+2+4 = 5)
again: n@10 in Ubasic means n mod 10

note 3: Ubasic has this neat prime checker:
if prmdiv(n) = n then n is prime
With Ubasic, "cancel for" means get the hell out of this loop

note 4: for what you're paying me to do this, I ain't STACKing 'em !!

Lemme know if you NOW get 9 solutions...after fixing your bugs :)

Very neat program!  I know mine looks very long and clumsy compared to yours, but it's the top-down approach that is so widely taught today. The method means any non-programmer can understand the program from one very brief main routine, which should be understandable even to those who don't know any programming languages.  In my case, the main routine consists merely of:

for n = 10001 to 99967 #2
  if prime(n)
    if inSequence()
next n

Now to the "missing" four answers.  You're right that they're there.  The fault is that I didn't specify the problem correctly, and I'm going to have to change it.  I intended to say that, in the span of 30 primes in any sequence, there were only 6 primes altogether, spaced as detailed.  I didn't make this clear at all, for which my apologies.

Example:  you found a sequence beginning 26681.  This consists of:

26681, 26683, 26687, 26693, 26699, 26701, 26711

The 26699 slips in there, and isn't part of the specified sequence.  Your code didn't find it because it works differently to mine (no stack - as you say, at the wages I'm paying, you can't put frills in). 

Sorry about this, Denis!  Thanks for pointing the error out.  I'll be putting my website straight on that.


Site design/maintenance: Dave Ellis E-mail me!
Last Updated: February 22nd, 2004.