Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/examples/bench/bytesiev.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ Copyright BYTE magazine
\ (* The Sieve of Eratosthanes, compiled *) /


DECIMAL

8192   CONSTANT size
size string flags

: DO-PRIME
        flags size 1 FILL
        0 size 0
        DO      flags I + C@
                IF   I DUP +  3 +  DUP  I +
                     BEGIN      DUP size <
                     WHILE      0 OVER flags + C!
                                OVER +
                     REPEAT
                     DROP DROP 1+
             THEN
        LOOP ;

: PRIMES
        ." Going to do 25 iterations."
        0  25 0 DO DROP
                    DO-PRIME
                 LOOP
        CR .    ." primes found," ;

        CR ." Enter PRIMES to test."

                        \ (* End of Information *)
CR PRIMES CR

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].