Emirp primes: Difference between revisions

m
(Initial FutureBasic task solution added)
 
(3 intermediate revisions by 3 users not shown)
Line 422:
948349
</pre>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<syntaxhighlight lang="bbcbasic"> 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$</syntaxhighlight>
{{out}}
<pre>First 20 emirps are: 13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389
Emirps between 7700 and 8000 are: 7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963
The 10,000th emirp is: 948349</pre>
 
=={{header|C}}==
Line 799 ⟶ 835:
=={{header|Delphi}}==
See [https://rosettacode.org/wiki/Emirp_primes#Pascal Pascal].
 
=={{header|EasyLang}}==
<syntaxhighlight>
fastfunc isprim num .
i = 2
while i <= sqrt num
if num mod i = 0
return 0
.
i += 1
.
return 1
.
func isemirp n .
if isprim n = 0
return 0
.
m = n
while m > 0
d = m mod 10
m = m div 10
rev = rev * 10 + d
.
if rev = n
return 0
.
return isprim rev
.
m = 2
write "First 20 emirps: "
while cnt < 20
if isemirp m = 1
write m & " "
cnt += 1
.
m += 1
.
print ""
write "Emirps between 7700 8000: "
for m = 7700 to 8000
if isemirp m = 1
write m & " "
.
.
print ""
m = 2
cnt = 0
repeat
cnt += isemirp m
until cnt = 10000
m += 1
.
print "The 10000th emirp: " & m
</syntaxhighlight>
{{out}}
<pre>
First 20 emirps: 13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389
Emirps between 7700 8000: 7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963
The 10000th emirp: 948349
</pre>
 
=={{header|Elixir}}==
Line 4,781 ⟶ 4,877:
=={{header|Wren}}==
{{libheader|Wren-math}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
 
var isEmirp = Fn.new{ |n|
2,083

edits