1 'PRIMENUM.BAS--uses GWBasic or QBasic 2 'hh Sept./85 3 DIM P(3600) 10 GOTO 5000 99 '-------------prime number generater S.R. 100 P(1) = 2: P(2) = 3: T = 2: R = 1 110 FOR G = K TO 32767 STEP 2 120 J = 2 130 IF R * R < G THEN R = R + 1 140 IF G MOD P(J) = O THEN 200 ELSE IF P(J) >= R THEN 150 ELSE J = J + 1: GOTO 140 150 T = T + 1: P(T) = G: IF F = 1 THEN PRINT G, 160 IF F = 3 THEN RETURN 170 A = B: B = G: IF A + 2 <> B OR F <> 2 THEN 190 180 Q = Q + 1: IF Q MOD 2 = 1 THEN PRINT A, B, ELSE PRINT A, B, "Pairs "; Q - 1; " and "; Q 190 IF G = 32749 THEN FF = 1 200 GOSUB 700 210 IF ST = 1 THEN 230 220 NEXT G 230 RETURN 299 '------------lo.res.spiral plot S.R. 300 ON D GOTO 310, 320, 330, 340 310 Y = Y + 3: GOTO 345 320 X = X + 1: GOTO 345 330 Y = Y - 3: GOTO 345 340 X = X - 1 345 IF FF2 THEN 355 350 LOCATE X, Y: IF P THEN PRINT CHR\$(219); CHR\$(219); CHR\$(219); ELSE PRINT CHR\$(216); CHR\$(216); CHR\$(216); : GOTO 360 353 GOTO 360 355 IF P THEN Y = Y - 1: LOCATE X, Y: PRINT G; : Y = Y + 1: GOTO 360 357 LOCATE X, Y: PRINT CHR\$(216); CHR\$(216); CHR\$(216); 360 LP = LP + 1 370 IF LP < S GOTO 420 380 D = D + 1 390 LP = 1 400 IF D = 2 OR D = 4 THEN S = S + 1 410 IF D > 4 THEN D = 1 420 RETURN 499 '------------hi.res.spiral plot S.R. 500 ON D GOTO 510, 520, 530, 540 510 X = X + 1: GOTO 550 520 Y = Y + 1: GOTO 550 530 X = X - 1: GOTO 550 540 Y = Y - 1 550 PSET (X, Y), P 560 LP = LP + 1 570 IF LP < S THEN 620 580 D = D + 1 590 LP = 1 600 IF D = 2 OR D = 4 THEN S = S + 1 610 IF D > 4 THEN D = 1 620 RETURN 699 '------------abort S.R. 700 B\$ = INKEY\$ 710 IF B\$ = "M" OR B\$ = "m" THEN ST = 1: GOTO 730 720 IF FF = 1 THEN 700 730 RETURN 999 '------------check for prime S.R. 1000 FOR I = 2 TO SR 1010 IF X MOD I = 0 THEN PN = 0: GOTO 1040 1020 NEXT I 1030 PN = 1 1040 RETURN 4999 '-----------start of Mainline Program 5000 KEY OFF 5005 A\$ = "Press 'PAUSE'(or ^S) to stop--'SPACEBAR' to continue--'M' for Main Menu" 5007 X\$ = " " 5010 GOSUB 7000 5020 GOTO 7200 5099 '------------------------------------ 5100 TITLE\$ = " PRIME NUMBER GENERATER " 5110 TITLE1\$ = "" 5120 TITLE2\$ = "" 5130 GOSUB 7030 5135 LOCATE 25, 5: PRINT A\$; 5137 LOCATE 4, 1 5140 F = 1: K = 3: ST = 0 5150 PRINT 2, 3, 5160 GOSUB 100 5170 GOSUB 7000 5180 GOTO 7200 5199 '------------------------------------ 5200 TITLE\$ = " PRIME PAIRS GENERATER " 5210 TITLE1\$ = "" 5220 TITLE2\$ = "" 5230 GOSUB 7030 5240 F = 2: K = 3: Q = 0: B = 3: ST = 0 5244 LOCATE 25, 5: PRINT A\$; 5247 LOCATE 4, 1 5250 GOSUB 100 5260 GOSUB 7000 5270 GOTO 7200 5299 '------------------------------------ 5300 TITLE\$ = " CHECK FOR PRIME " 5310 TITLE1\$ = "" 5320 TITLE2\$ = "" 5330 GOSUB 7030 5350 LOCATE 25, 27: COLOR 0, 7: PRINT "Enter 1 to Exit"; : COLOR 7, 0 5360 LOCATE 10, 10: INPUT "What number do you wish checked for prime (1--32767)"; X 5370 IF X = 1 THEN 5500 5380 LOCATE 18, 10 5390 IF X <> INT(X) THEN PRINT X; " is not an integer ": GOTO 5360 5400 IF X < 1 OR X > 32767 THEN PRINT X; " is out of range ": GOTO 5360 5410 LOCATE 18, 10: PRINT X\$ 5420 SR = SQR(X) 5430 GOSUB 1000 5440 IF PN = 2 THEN 6490 5450 LOCATE 18, 10 5460 IF PN = 1 THEN PRINT X; " is a prime number": GOTO 5480 5470 PRINT X; " is a composite number" 5480 LOCATE 10, 10: PRINT X\$ 5490 GOTO 5360 5500 GOSUB 7000: GOTO 7200 5599 '------------------------------------ 5600 TITLE\$ = " HIGH RES. SPIRAL PLOT " 5610 TITLE1\$ = "" 5620 TITLE2\$ = "" 5630 GOSUB 7030 5632 LOCATE 14, 1: INPUT "Do you want a vacant cell in center of plot (Y/N) "; C\$ 5634 IF C\$ = "Y" OR C\$ = "y" THEN FF3 = 1 ELSE FF3 = 0 5640 FOR X = 1 TO 1000: NEXT X 5650 SCREEN 2: CLS 5660 LOCATE 25, 1: PRINT "Plotting to Prime Number " 5670 LOCATE 25, 36: PRINT "Controls--> 'PAUSE' (or ^S), 'SPACEBAR', 'M'"; 5680 F = 3: K = 3: ST = 0: FF = 0 5685 LOCATE , , 0 5690 X = 320: Y = 90: LP = 0: S = 1: D = 1: P = 1 5695 IF FF3 THEN LP = 1: S = 2: D = 2 5700 FOR J = 1 TO 3 5710 GOSUB 500 5720 NEXT J 5730 G1 = 4: P = 0: GOSUB 100 5740 LOCATE 25, 28: PRINT G; 5750 FOR G2 = G1 TO G - 1 5760 GOSUB 500 5770 NEXT G2 5780 P = 1: GOSUB 500 5790 G1 = G + 1: K = G1 + 1: P = 0 5800 IF G1 = 32750 THEN FF = 1 5810 GOSUB 700 5820 IF ST = 1 THEN GOTO 5850 5830 GOSUB 110 5840 GOTO 5740 5850 SCREEN 0 5860 GOSUB 7000 5870 GOTO 7200 5899 '------------------------------------ 5900 TITLE\$ = " LO. RES. SPIRAL PLOT " 5910 TITLE1\$ = "" 5920 TITLE2\$ = "" 5930 GOSUB 7030 5940 LOCATE 25, 1: PRINT "Plotting to Prime Number "; 5950 LOCATE 25, 36: PRINT "Controls -->> 'PAUSE'(or ^S), 'SPACEBAR', 'M'"; 5952 LOCATE 12, 1: INPUT "Do you wish Prime Numbers to appear in plot (Y/N) "; C\$ 5954 IF C\$ = "Y" OR C\$ = "y" THEN FF2 = 1 ELSE FF2 = 0 5955 LOCATE 14, 1: INPUT "Do you want a vacant cell in center of plot (Y/N) "; C\$ 5956 IF C\$ = "Y" OR C\$ = "y" THEN FF3 = 1 ELSE FF3 = 0 5957 LOCATE 12, 1: PRINT X\$ 5958 LOCATE 14, 1: PRINT X\$ 5959 LOCATE , , 0 5960 F = 3: K = 3: ST = 0: FF = 0 5970 X = 12: Y = 40: LP = 0: S = 1: D = 1: P = 1 5975 IF FF3 THEN LP = 1: S = 2: D = 2 5980 FOR G = 1 TO 3 5990 GOSUB 300 6000 NEXT G 6010 G1 = 4: P = 0: GOSUB 100 6020 LOCATE 25, 28: PRINT G; 6030 FOR G2 = G1 TO G - 1 6040 GOSUB 300 6050 IF X = 1 AND Y = 7 AND FF3 = 0 THEN FF = 1: GOTO 6090 6055 IF X = 1 AND Y = 4 AND FF3 = 1 THEN FF = 1: GOTO 6090 6060 NEXT G2 6070 P = 1: GOSUB 300 6080 G1 = G + 1: K = G1 + 1: P = 0 6090 GOSUB 700 6100 IF ST = 1 THEN GOTO 6130 6110 GOSUB 110 6120 GOTO 6020 6130 GOSUB 7000 6140 GOTO 7200 6399 '------------------------------------ 6400 TITLE\$ = " LINEAR PLOT OF PRIMES " 6410 TITLE1\$ = "" 6420 TITLE2\$ = "" 6430 GOSUB 7030 6440 LOCATE 12, 1: INPUT "What width of plot do you wish 3--80 "; C 6450 IF C < 3 OR C > 80 THEN LOCATE 14, 1: PRINT C; " is out of range": GOTO 6440 6460 IF C <> INT(C) THEN LOCATE 14, 1: PRINT C; " is not an integer": GOTO 6440 6470 FOR X = 1 TO 1000: NEXT X 6480 F = 3: K = 3: FF = 0: ST = 0: CLS 6485 LOCATE , , 0 6490 LOCATE 25, 1: PRINT "Plotting to Prime Number "; 6500 LOCATE 25, 36: PRINT "Controls-->'PAUSE'(or ^S), 'SPACEBAR', 'M'" 6510 LOCATE 1, 1: PRINT CHR\$(219); CHR\$(219); CHR\$(219) 6520 X = 1: Y = 4: G1 = 4: GOSUB 100 6530 LOCATE 25, 28: PRINT G; 6540 FOR G2 = G1 TO G - 1 6550 LOCATE X, Y: PRINT CHR\$(216); 6560 Y = Y + 1: IF Y > C THEN Y = 1: X = X + 1: IF X = 25 THEN FF = 1: GOTO 6620 6570 NEXT G2 6580 G1 = G + 1 6590 LOCATE X, Y: PRINT CHR\$(219); 6600 Y = Y + 1: IF Y > C THEN Y = 1: X = X + 1: IF X = 25 THEN FF = 1: GOTO 6620 6610 K = G1 + 1 6620 GOSUB 700 6630 IF ST = 1 THEN 6660 6640 GOSUB 110 6650 GOTO 6530 6660 GOSUB 7000 6670 GOTO 7200 6999 '-----------Main Title 7000 TITLE\$ = " **** PRIME NUMBERS **** " 7010 TITLE1\$ = " " 7020 TITLE2\$ = "Harvey Heinz Sept. 1985" 7025 '-----------entry for sub titles 7030 LENGTH = LEN(TITLE\$) 7040 TOPSIDE\$ = CHR\$(201) + STRING\$(LENGTH, CHR\$(205)) + CHR\$(187) 7050 BOTTOM\$ = CHR\$(200) + STRING\$(LENGTH, CHR\$(205)) + CHR\$(188) 7100 CLS 7110 PRINT TAB(23); TOPSIDE\$ 7120 PRINT TAB(23); CHR\$(186); TITLE\$; CHR\$(186) 7130 IF LEN(TITLE1\$) > 0 THEN PRINT TAB(23); CHR\$(186); TITLE1\$; CHR\$(186) 7140 IF LEN(TITLE2\$) > 0 THEN PRINT TAB(23); CHR\$(186); TITLE2\$; CHR\$(186) 7150 PRINT TAB(23); BOTTOM\$ 7160 RETURN 7199 '------------------------------------ 7200 PRINT : PRINT 7210 PRINT TAB(29); "*** MENU ***" 7220 PRINT TAB(24); "1..Prime Number Generater" 7230 PRINT TAB(24); "2..Prime Pairs Generater " 7240 PRINT TAB(24); "3..Test for Prime" 7250 PRINT TAB(24); "4..Linear Plot of Primes" 7260 PRINT TAB(24); "5..Spiral Plot of Primes" 7270 PRINT TAB(24); "6..High Res. Spiral Plot" 7280 PRINT TAB(24); "7..Quit Program" 7290 LOCATE 22, 24, 1: PRINT "Which function would you like (1 - 7) "; 7300 INPUT A 7310 IF A < 1 OR A > 7 THEN 7290 7320 ON A GOTO 5100, 5200, 5300, 6400, 5900, 5600, 7400 7399 ' 7400 CLS : KEY ON 7410 END 7500 ' 7510 'NOTES 7520 'Prime number generater is based on an algorithym in Apple Computer 7530 'Integer Basic Manual, with mods to make it universal for all routines. 7540 'F1,F2,F3 are flags for Prime no. gen;,Prime pair gen. & spiral rout. 7550 'Linear plot---note greater order with widths of 12,24,36,& 72 7560 'Spiral plots---note greater order with vacant center cell. 7570 'All routines limited to 32767 because of limit on 'MOD' 7580 ' 7590 'I would appreciate comments regarding this program or any aspect of 7600 'Recreational Mathematics for personal computers. 7610 ' 7620 'Harvey Heinz (604)-584-5501