# Primes by Trial Division - TI LOGO

22 March 2020

TI LOGO is very close to Terrapin Logo PLUS, but there is no LOCAL (all procedure
variables are already LOCAL). There is also no included routine for REMAINDER or for
directly selecting the *n*th element of a list, so these procedures must be
defined.

TO REMAINDER :NUM :DIV OUTPUT :NUM - (:NUM / :DIV) * :DIV END TO ITEM :N :LIST IF :N = 1 OUTPUT FIRST :LIST OUTPUT ITEM (:N - 1) (BUTFIRST :LIST) END TO PRIMES :N MAKE "PRIMES [] MAKE "COUNT 2 MAKE "FOUND 0 CONTINUE: PRINT :COUNT MAKE "PRIMES (LPUT :COUNT :PRIMES) MAKE "FOUND (:FOUND + 1) IF :FOUND = :N THEN STOP NOTPRIME: MAKE "COUNT (:COUNT + 1) MAKE "I 1 NEXTQ: IF REMAINDER :COUNT (ITEM :I :PRIMES) = 0 THEN GO "NOTPRIME MAKE "I (:I + 1) IF NOT :I > :FOUND THEN GO "NEXTQ GO "CONTINUE END