Primes by Trial Division - Logotron LOGO
16 August 2018
Logotron LOGO is similar to Terrapin LOGO, but lacks scoped variables and many useful program flow control functions.
TO WHILE :COND :PROC IF NOT RUN :COND [ STOP ] RUN :PROC WHILE :COND :PROC END TO ISPRIME :N MAKE "I 1 REPEAT :FOUND [ IF (REMAINDER :COUNT ITEM :I :PRIMES) = 0 [ OP 1 ] [ MAKE "I (1 + :I) ] ] OP 0 END TO PRIMES :N MAKE "PRIMES [] MAKE "COUNT 2 MAKE "FOUND 0 WHILE [ :FOUND < :N ] [ IF (ISPRIME :COUNT) = 0 [ PR :COUNT MAKE "PRIMES (LPUT :COUNT :PRIMES) MAKE "FOUND (1 + :FOUND) ] [] MAKE "COUNT (1 + :COUNT) ] END