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.

Format
Plain text
Post date
2019-04-23 11:55
Publication Period
Unlimited
  1. 1 REM A PROGRAM TO COUNT PRIMES IN COLOR COMPUTER BASIC
  2. 2 REM JOEL MATTHEW REES, APRIL 2019, AMAGASAKI, JAPAN
  3. 3 REM COPYRIGHT 2019, JOEL MATTHEW REES
  4. 4 REM MAY BE FREELY USED FOR NON-COMMERCIAL PURPOSES.
  5. 10 MAX=255
  6. 20 DIM PRIMES(MAX)
  7. 30 FINAL = MAX/2
  8. 40 PRIMES(0)=0
  9. 50 PRIMES(1)=0
  10. 60 FOR I=2 TO MAX: PRIMES(I)=1: NEXT
  11. 70 FOR I=2 TO FINAL
  12. 80 FOR J=I+I TO MAX STEP I
  13. 90 PRIMES(J)=0
  14. 100 NEXT J
  15. 110 NEXT I
  16. 115 COUNT=0
  17. 120 FOR I=0 TO MAX
  18. 130 PRINT I;" IS ";
  19. 140 IF PRIMES(I)=0 THEN PRINT "NOT "; ELSE COUNT=COUNT+1
  20. 150 PRINT "PRIME."
  21. 160 NEXT I
  22. 170 PRINT COUNT;" PRIMES LESS THAN "; MAX; "."
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text