This is the fastest version I tried, and it should work as is if a machine has a BASIC that supports ELSE, long enough lines, and Microsoft like syntax.
Line 0 can be deleted for anything other than a CoCo. The TIMER related stuff is also CoCo specific, and should be replaced with any systems specific time code.
This algorithm only checks odd numbers for I since evens are never primes, and it only needs to check numbers for J up to I/2 since anything larger won't divide into I at least 2 times.
Defining the variables at the top cut about a second off of the time. This is common on all Microsoft BASICs.
Placing most accessed variables at the start of the variable table first makes it quicker to find them, though I'm not sure if X or J should be first..
Deleting spaces would also make it faster but I left them in for readability.
*edit* Deleting spaces took almost a second off of the times below.
This takes about 32 seconds on my enhanced MC-10 BASIC, and the MC-10 is only clocked at .89 MHz.
I could run it on the CoCo but I have to type it in by hand since the VCC emulator doesn't have a quick type feature, but it should take about 20-22 seconds.
0 POKE 65495,0
110 PRINT "Welcome to the prime number generator."
115 N = 32767
120 INPUT "Upper limit (32767)";N
130 FOR I = 3 TO N STEP 2:FOR J = 2 TO I/2:X=I/J:IF X <> INT(X) THEN NEXT J:PRINT I;:NEXT I:ELSE PRINT ".";:NEXT I
220 FINAL = TIMER/60
240 PRINT "TIME ELAPSED IN SECONDS: ";FINAL
Edited by JamesD, Thu Nov 16, 2017 4:00 PM.