home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine 1995 / ARCHIVE95.iso / discs / pipeline / 5_11 / Primes / c_Prime next >
Text File  |  1992-05-09  |  2KB  |  69 lines

  1. %OP%VS4.12 (10-Feb-92), Gerald Fitton, R4000 2915 6625 6368 
  2. %OP%TNN
  3. %OP%WRN
  4. %OP%DP0
  5. %OP%IRN
  6. %OP%PL66
  7. %OP%TM4
  8. %OP%HM2
  9. %OP%FM2
  10. %OP%BM4
  11. %OP%LM5
  12. %OP%PT1
  13. %OP%PDPipeLine
  14. %OP%WC1008,2252,404,1748,0,1,0,0
  15. %OP%NDnumbertested,A22
  16. %OP%NDlast_prime,B9
  17. %OP%NDnumber_under_test,B10
  18. %OP%NDhighest_divisor,B11
  19. %OP%NDarray_pointer,B12
  20. %OP%NDprime_at_pointer,B13
  21. %OP%NDremainder,B14
  22. %CO:A,46,72%Comments and Commands
  23.  
  24. Custom function to find the next prime number
  25.                  given all lower prime numbers
  26.  
  27. %V%%L%function("nextprime","lowerprimes:array")
  28.  
  29. Declare all local variables as names
  30. %V%%L%set_name("last_prime",B9)
  31. %V%%L%set_name("number_under_test",B10)
  32. %V%%L%set_name("highest_divisor",B11)
  33. %V%%L%set_name("array_pointer",B12)
  34. %V%%L%set_name("prime_at_pointer",B13)
  35. %V%%L%set_name("remainder",B14)
  36.  
  37. Initialise local variables using set_value(name,value)
  38. %V%%L%set_value(last_prime,max(@lowerprimes))
  39. %V%%L%set_value(number_under_test,last_prime)
  40. %V%%L%set_value(highest_divisor,int(sqr(last_prime))+1)
  41.  
  42. %V%%L%repeat
  43. %V%%L%   set_value(number_under_test,number_under_test+2)
  44. %V%%L%   set_value(array_pointer,0)
  45.  
  46. %V%%L%   repeat
  47. %V%%L%      set_value(array_pointer,array_pointer+1)
  48. %V%%L%      set_value(prime_at_pointer,index(@lowerprimes,1,array_pointer))
  49. %V%%L%      set_value(remainder,mod(number_under_test,prime_at_pointer))
  50. %V%%L%   until((remainder=0)|(prime_at_pointer>highest_divisor))
  51.  
  52. %V%%L%until(prime_at_pointer>highest_divisor)
  53.  
  54. %V%%L%result(number_under_test)
  55. %CO:B,6,12%Value
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. %V%%R%61
  64. %V%%R%67
  65. %V%%R%8
  66. %V%%R%2
  67. %V%%R%3
  68. %V%%R%1
  69. %CO:C,20,20%