RosettaCodeData/Task/Emirp-primes/BBC-BASIC/emirp-primes.basic
2023-12-16 21:33:55 -08:00

29 lines
936 B
Text

REM Taking advantage of inbuilt assembler to implement ultra fast Prime tester!
DIM P% 127:[OPT 0
.F% pop eax:mov eax,0:.T% ret:.M% mov eax,ecx:xor edx,edx:div ebx:cmp edx,0:jz F%:ret
.E% mov ebx,2:call M%:mov ebx,3:call M%:mov ebx,5:.W% mov edx,ebx:imul edx,ebx
cmp edx,ecx:jg T%:call M%:add ebx,2:call M%:add ebx,4:jmp W%:]
DEF FNIsPrime(C%)=USRE%
N%=0
P%=11
PRINT "First 20 emirps are:";
WHILE N%<10000
P%+=2
IF FNIsPrime(P%) THEN
R%=VALFNRev(STR$P%)
IF P%<>R% IF FNIsPrime(R%) THEN
IF N%<20 OR (P%>7699 AND P%<8001) PRINT " ";P%;
N%+=1
IF N%=20 PRINT '"Emirps between 7700 and 8000 are:";
ENDIF
ENDIF
ENDWHILE
PRINT '"The 10,000th emirp is: ";P%
END
DEF FNRev(n$)
Q%=!^n$
L%=LENn$-1
FOR I%=0 TO L%/2 SWAP Q%?I%, Q%?(L%-I%) NEXT
=n$