home *** CD-ROM | disk | FTP | other *** search
/ Carousel Volume 2 #1 / carousel.iso / mactosh / lang / mpw_maci.hqx / IconSamples.pit / sieve.icn < prev    next >
Encoding:
Text File  |  1987-01-21  |  530 b   |  20 lines

  1. #
  2. #          S I E V E   O F   E R A T O S T H E N E S
  3. #
  4.  
  5. #  This program illustrates the use of sets in implementing the
  6. #  classical sieve algorithm for computing prime numbers.
  7.  
  8. procedure main()
  9.    local limit, s, i
  10.    limit := 100
  11.    s := set([])
  12.    every insert(s,1 to limit)
  13.    every member(s,i := 2 to limit) do
  14.       every delete(s,i + i to limit by i)
  15.    primes := sort(s)
  16.    write("There are ",*primes," primes in the first ",limit," integers.")
  17.    write("The primes are:")
  18.    every write(right(!primes,*limit + 1))
  19. end
  20.