Annotation of 43BSD/contrib/icon/samples/sieve.icn, revision 1.1.1.1

1.1       root        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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.