Building a sieve and counting primes in BASIC on the venerable Color Computer. Can go up to 4,100 primes in a 32K machine, see MAX on line 10. 4,100 requires three minutes or so.
- 1 REM A PROGRAM TO COUNT PRIMES IN COLOR COMPUTER BASIC
- 2 REM JOEL MATTHEW REES, APRIL 2019, AMAGASAKI, JAPAN
- 3 REM COPYRIGHT 2019, JOEL MATTHEW REES
- 4 REM MAY BE FREELY USED FOR NON-COMMERCIAL PURPOSES.
- 10 MAX=255
- 20 DIM PRIMES(MAX)
- 30 FINAL = MAX/2
- 40 PRIMES(0)=0
- 50 PRIMES(1)=0
- 60 FOR I=2 TO MAX: PRIMES(I)=1: NEXT
- 70 FOR I=2 TO FINAL
- 80 FOR J=I+I TO MAX STEP I
- 90 PRIMES(J)=0
- 100 NEXT J
- 110 NEXT I
- 115 COUNT=0
- 120 FOR I=0 TO MAX
- 130 PRINT I;" IS ";
- 140 IF PRIMES(I)=0 THEN PRINT "NOT "; ELSE COUNT=COUNT+1
- 150 PRINT "PRIME."
- 160 NEXT I
- 170 PRINT COUNT;" PRIMES LESS THAN "; MAX; "."