From: Virgil on
In article
<0dde68ee-7733-4500-9b55-34098bb88f5d(a)g12g2000yqa.googlegroups.com>,
Yann <kdo4973(a)gmail.com> wrote:

> Virgil's version with trivial speed-oriented modifications :
> down to 25.69 sec (90.5 bytes, #D361h)
>
> \<<
> 1 DUPDUP 4 ROLL
> START
> NEXTPRIME SWAP OVER * SWAP
> NEXT
> 0 SWAP NEXTPRIME 4 ROLL
> FOR X
> X PICK3 GCD 1 == +
> 2 STEP NIP
> \>>

I cannot get the above to work at all.

Are you sure that you didn't mean

\<<
1 DUPDUP 4 ROLL
START
NEXTPRIME SWAP OVER * SWAP
NEXT DROP
0 1 4 ROLL
FOR X
X PICK3 GCD 1 == +
2 STEP NIP
\>>

in which the only change is to replace my "NEXT" with "2 STEP"?
From: Wes on
On Dec 2, 10:07 am, Virgil <Vir...(a)home.esc> wrote:
> I cannot get the above to work at all.

> 0 SWAP NEXTPRIME 4 ROLL

Perhaps he meant

1 SWAP NEXTPRIME 4 ROLL


Besides "2 NEXT", here are a couple of more small tweaks:

If you don't mind using LASTARG, you can save a 2.5 byte instruction
if you replace

NEXTPRIME SWAP OVER * SWAP

with

NEXTPRIME * LASTARG NIP

and if you don't mind putting the 2.5 bytes back,

1 DUPDUP 4 ROLL

can be replace with

1 2 DUP 4 ROLL

for a tiny speedup. This leaves 2 out of your product, but if you're
using "2 STEP" then you're not checking even numbers anyway, and I
figure GCD might be slightly faster with a smaller value.

Here's a summary of what I think are the best combinations of code.
Hats off to Virgil for his clever algorithm.

@ best size*runtime: 85 bytes, 30.0192 seconds = 2.49 KB*sec
\<<
1 DUPDUP 4 ROLL
START
NEXTPRIME * LASTARG NIP
NEXT DROP
0 1 4 ROLL
FOR X
X PICK3 GCD 1 == +
2 STEP
NIP
\>>


@ fastest: 90.5 bytes, 29.8118 seconds = 2.63 KB*sec
\<<
1 2 DUP 4 ROLL
START
NEXTPRIME * LASTARG NIP
NEXT
1 SWAP NEXTPRIME 4 ROLL
FOR X
X PICK3 GCD 1 == +
2 STEP
NIP
\>>


@ smallest: 79.5 bytes, 187.9637 sec = 14.59 KB*sec
\<<
2. 2. PICK3
START
SWAP OVER NEXTPRIME
NEXT
SWAP \->LIST 0. 1. 4. ROLL
FOR I
I PICK3 MOD 0. POS NOT +
NEXT
NIP
\>>


-wes
From: Wes on
On Dec 2, 8:50 pm, Wes <wjltemp...(a)yahoo.com> wrote:
> @ best size*runtime: 85 bytes, 30.0192 seconds = 2.49 KB*sec
> @ fastest: 90.5 bytes, 29.8118 seconds = 2.63 KB*sec
> @ smallest: 79.5 bytes, 187.9637 sec = 14.59 KB*sec

Hang on, I see another improvement on two of these. Use Virgil's GCD
idea, but instead of using a FOR loop in the 2nd half of the program,
use SEQ and process the list. For really large values, this list
might take up a lot of memory, but it seems to run pretty well with
the test values.

@ best size*runtime: 82.5 bytes(#929Eh), 28.1229 seconds = 2.27 KB*sec
\<<
1 DUPDUP 4 ROLL
START
NEXTPRIME * LASTARG NIP
NEXT
DROP RCLVX DUP 1 5 ROLL 2 SEQ
GCD 1 - NOT \GSLIST
\>>


@ fastest: 93 bytes(#18B7h), 27.7733 seconds = 2.52 KB*sec
\<<
1 2 DUP 4 ROLL
START
NEXTPRIME * LASTARG NIP
NEXT
NEXTPRIME RCLVX DUP ROT 5 ROLL 2 SEQ
GCD 1 - NOT \GSLIST 1 +
\>>

-wes
First  |  Prev  | 
Pages: 1 2 3 4
Prev: StreamSmart
Next: UH calculator contest challenge