home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Archive Magazine 1996
/
ARCHIVE_96.iso
/
discs
/
gerald
/
5_11
/
Primes
/
c_Prime
next >
Wrap
Text File
|
1992-05-09
|
2KB
|
69 lines
%OP%VS4.12 (10-Feb-92), Gerald Fitton, R4000 2915 6625 6368
%OP%TNN
%OP%WRN
%OP%DP0
%OP%IRN
%OP%PL66
%OP%TM4
%OP%HM2
%OP%FM2
%OP%BM4
%OP%LM5
%OP%PT1
%OP%PDPipeLine
%OP%WC1008,2252,404,1748,0,1,0,0
%OP%NDnumbertested,A22
%OP%NDlast_prime,B9
%OP%NDnumber_under_test,B10
%OP%NDhighest_divisor,B11
%OP%NDarray_pointer,B12
%OP%NDprime_at_pointer,B13
%OP%NDremainder,B14
%CO:A,46,72%Comments and Commands
Custom function to find the next prime number
given all lower prime numbers
%V%%L%function("nextprime","lowerprimes:array")
Declare all local variables as names
%V%%L%set_name("last_prime",B9)
%V%%L%set_name("number_under_test",B10)
%V%%L%set_name("highest_divisor",B11)
%V%%L%set_name("array_pointer",B12)
%V%%L%set_name("prime_at_pointer",B13)
%V%%L%set_name("remainder",B14)
Initialise local variables using set_value(name,value)
%V%%L%set_value(last_prime,max(@lowerprimes))
%V%%L%set_value(number_under_test,last_prime)
%V%%L%set_value(highest_divisor,int(sqr(last_prime))+1)
%V%%L%repeat
%V%%L% set_value(number_under_test,number_under_test+2)
%V%%L% set_value(array_pointer,0)
%V%%L% repeat
%V%%L% set_value(array_pointer,array_pointer+1)
%V%%L% set_value(prime_at_pointer,index(@lowerprimes,1,array_pointer))
%V%%L% set_value(remainder,mod(number_under_test,prime_at_pointer))
%V%%L% until((remainder=0)|(prime_at_pointer>highest_divisor))
%V%%L%until(prime_at_pointer>highest_divisor)
%V%%L%result(number_under_test)
%CO:B,6,12%Value
%V%%R%61
%V%%R%67
%V%%R%8
%V%%R%2
%V%%R%3
%V%%R%1
%CO:C,20,20%