home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / PowerLisp 1.01 / examples / primes.lisp < prev    next >
Encoding:
Text File  |  1992-12-15  |  2.9 KB  |  98 lines  |  [TEXT/ROSA]

  1. ;
  2. ;        File:        primes.lisp
  3. ;        Contents:    Lisp program to generate all the prime numbers
  4. ;                    between 1 and n. It is quick and dirty, and uses
  5. ;                    a brute force approach to calculating them (i.e. it
  6. ;                    tries all possibilites).
  7. ;
  8. (defun primes (n1 n2)
  9.     "Generate all the prime numbers between n1 and n2"
  10.     (do ((i n1 (1+ i)))
  11.         ((> i n2))
  12.         (block inner
  13.             (do ((j 2 (1+ j)))
  14.                 ((>= j i) (print i))
  15.                 (if (zerop (mod i j))    ; if found a divisor
  16.                      (return-from inner)))))) 
  17.  
  18. ;(defun modulo (n1 n2)
  19. ;    (cadr (multiple-value-list (truncate n1 n2))))
  20. #|
  21. (defun print-primes (x &aux (counter 0))
  22.     (write #\Newline)
  23.     (write #\Tab)
  24.     (dolist (i x)
  25.         (write i)
  26.         (incf counter)
  27.         (if (zerop (mod counter 8))
  28.             (progn (write #\,)(write #\Newline) (write #\Tab))
  29.             (progn 
  30.                 (write #\,) 
  31.                 (write #\Tab) 
  32.                 (if (< i 100) (write #\Tab))))))
  33.  
  34. ;
  35. ;    Prime number list generated from above functions.
  36. ;
  37. (defvar *prime-numbers* '(
  38.     1         2         3         5         7         11         13         17 
  39.     19         23         29         31         37         41         43         47 
  40.     53         59         61         67         71         73         79         83 
  41.     89         97         101     103     107     109     113     127 
  42.     131     137     139     149     151     157     163     167 
  43.     173     179     181     191     193     197     199     211 
  44.     223     227     229     233     239     241     251     257 
  45.     263     269     271     277     281     283     293     307 
  46.     311     313     317     331     337     347     349     353 
  47.     359     367     373     379     383     389     397     401 
  48.     409     419     421     431     433     439     443     449 
  49.     457     461     463     467     479     487     491     499 
  50.     503     509     521     523     541     547     557     563 
  51.     569     571     577     587     593     599     601     607 
  52.     613     617     619     631     641     643     647     653 
  53.     659     661     673     677     683     691     701     709 
  54.     719     727     733     739     743     751     757     761 
  55.     769     773     787     797     809     811     821     823 
  56.     827     829     839     853     857     859     863     877 
  57.     881     883     887     907     911     919     929     937 
  58.     941     947     953     967     971     977     983     991 
  59.     997     1009     1013     1019     1021     1031     1033     1039 
  60.     1049     1051     1061     1063     1069     1087     1091     1093 
  61.     1097    1201    1301    1511    2003    3001    5003    10007))
  62.  
  63. |#
  64. ;    1,        2,        3,        5,        7,        11,        13,        17,
  65. ;    19,        23,        29,        31,        37,        41,        43,        47,
  66. ;    53,        59,        61,        67,        71,        73,        79,        83,
  67. ;    89,        97,        101,    103,    107,    109,    113,    127,
  68. ;    131,    137,    139,    149,    151,    157,    163,    167,
  69. ;    173,    179,    181,    191,    193,    197,    199,    211,
  70. ;    223,    227,    229,    233,    239,    241,    251,    257,
  71. ;    263,    269,    271,    277,    281,    283,    293,    307,
  72. ;    311,    313,    317,    331,    337,    347,    349,    353,
  73. ;    359,    367,    373,    379,    383,    389,    397,    401,
  74. ;    409,    419,    421,    431,    433,    439,    443,    449,
  75. ;    457,    461,    463,    467,    479,    487,    491,    499,
  76. ;    503,    509,    521,    523,    541,    547,    557,    563,
  77. ;    569,    571,    577,    587,    593,    599,    601,    607,
  78. ;    613,    617,    619,    631,    641,    643,    647,    653,
  79. ;    659,    661,    673,    677,    683,    691,    701,    709,
  80. ;    719,    727,    733,    739,    743,    751,    757,    761,
  81. ;    769,    773,    787,    797,    809,    811,    821,    823,
  82. ;    827,    829,    839,    853,    857,    859,    863,    877,
  83. ;    881,    883,    887,    907,    911,    919,    929,    937,
  84. ;    941,    947,    953,    967,    971,    977,    983,    991,
  85. ;    997,    1009,    1013,    1019,    1021,    1031,    1033,    1039,
  86. ;    1049,    1051,    1061,    1063,    1069,    1087,    1091,    1093,
  87. ;    1097,    1201,    1301,    1511,    2003,    3001,    5003,    10007,
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.