Find prime n such that reversed n is also prime: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 6: | Line 6: | ||
=={{header|11l}}== |
=={{header|11l}}== |
||
< |
<syntaxhighlight lang="11l">F is_prime(a) |
||
I a == 2 |
I a == 2 |
||
R 1B |
R 1B |
||
Line 18: | Line 18: | ||
L(n) 1..499 |
L(n) 1..499 |
||
I is_prime(n) & is_prime(Int(reversed(String(n)))) |
I is_prime(n) & is_prime(Int(reversed(String(n)))) |
||
print(n, end' ‘ ’)</ |
print(n, end' ‘ ’)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 27: | Line 27: | ||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
{{libheader|Action! Sieve of Eratosthenes}} |
{{libheader|Action! Sieve of Eratosthenes}} |
||
< |
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT" |
||
BYTE FUNC IsPrimeAndItsReverse(INT i BYTE ARRAY primes) |
BYTE FUNC IsPrimeAndItsReverse(INT i BYTE ARRAY primes) |
||
Line 61: | Line 61: | ||
OD |
OD |
||
PrintF("%E%EThere are %I primes",count) |
PrintF("%E%EThere are %I primes",count) |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Find_prime_n_such_that_reversed_n_is_also_prime.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Find_prime_n_such_that_reversed_n_is_also_prime.png Screenshot from Atari 8-bit computer] |
||
Line 71: | Line 71: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_Io; |
||
procedure Reverse_Prime is |
procedure Reverse_Prime is |
||
Line 125: | Line 125: | ||
New_Line; |
New_Line; |
||
Put_Line (Count'Image & " primes."); |
Put_Line (Count'Image & " primes."); |
||
end Reverse_Prime;</ |
end Reverse_Prime;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 2 3 5 7 11 13 17 31 |
<pre> 2 3 5 7 11 13 17 31 |
||
Line 135: | Line 135: | ||
=={{header|ALGOL W}}== |
=={{header|ALGOL W}}== |
||
< |
<syntaxhighlight lang="algolw">begin % find some primes whose digits reversed is also prime % |
||
% sets p( 1 :: n ) to a sieve of primes up to n % |
% sets p( 1 :: n ) to a sieve of primes up to n % |
||
procedure Eratosthenes ( logical array p( * ) ; integer value n ) ; |
procedure Eratosthenes ( logical array p( * ) ; integer value n ) ; |
||
Line 184: | Line 184: | ||
write( i_w := 1, s_w := 0, "Found ", pCount, " reversable primes below ", MAX_NUMBER ) |
write( i_w := 1, s_w := 0, "Found ", pCount, " reversable primes below ", MAX_NUMBER ) |
||
end |
end |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 193: | Line 193: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">print |
||
select 1..499 'x -> |
select 1..499 'x -> |
||
and? [prime? x][prime? to :integer reverse to :string x]</ |
and? [prime? x][prime? to :integer reverse to :string x]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 202: | Line 202: | ||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<syntaxhighlight lang="awk"> |
|||
<lang AWK> |
|||
# syntax: GAWK -f FIND_PRIME_N_FOR_THAT_REVERSED_N_IS_ALSO_PRIME.AWK |
# syntax: GAWK -f FIND_PRIME_N_FOR_THAT_REVERSED_N_IS_ALSO_PRIME.AWK |
||
BEGIN { |
BEGIN { |
||
Line 232: | Line 232: | ||
return( substr(str,start,1) revstr(str,start-1) ) |
return( substr(str,start,1) revstr(str,start-1) ) |
||
} |
} |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 243: | Line 243: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
< |
<syntaxhighlight lang="basic">10 DEFINT A-Z: MP=999: MX=500 |
||
15 MP=10^FIX(LOG(MX)/LOG(10)+1) |
15 MP=10^FIX(LOG(MX)/LOG(10)+1) |
||
20 DIM C(MP): C(0)=-1: C(1)=-1 |
20 DIM C(MP): C(0)=-1: C(1)=-1 |
||
Line 253: | Line 253: | ||
80 IF V>0 THEN R=10*R+V MOD 10: V=V\10: GOTO 80 |
80 IF V>0 THEN R=10*R+V MOD 10: V=V\10: GOTO 80 |
||
90 IF NOT C(R) THEN PRINT N, |
90 IF NOT C(R) THEN PRINT N, |
||
100 NEXT</ |
100 NEXT</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 2 3 5 7 11 |
<pre> 2 3 5 7 11 |
||
Line 264: | Line 264: | ||
=={{header|BCPL}}== |
=={{header|BCPL}}== |
||
< |
<syntaxhighlight lang="bcpl">get "libhdr" |
||
let sieve(prime, n) be |
let sieve(prime, n) be |
||
Line 295: | Line 295: | ||
writef("%N ",i) |
writef("%N ",i) |
||
wrch('*N') |
wrch('*N') |
||
$)</ |
$)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
||
=={{header|C}}== |
=={{header|C}}== |
||
< |
<syntaxhighlight lang="c">#include <stdbool.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 335: | Line 335: | ||
printf("\nCount = %u\n", count); |
printf("\nCount = %u\n", count); |
||
return 0; |
return 0; |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 347: | Line 347: | ||
=={{header|CLU}}== |
=={{header|CLU}}== |
||
< |
<syntaxhighlight lang="clu">sieve = proc (max: int) returns (array[bool]) |
||
prime: array[bool] := array[bool]$fill(0,max+1,true) |
prime: array[bool] := array[bool]$fill(0,max+1,true) |
||
prime[0] := false |
prime[0] := false |
||
Line 378: | Line 378: | ||
end |
end |
||
end |
end |
||
end start_up</ |
end start_up</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
||
=={{header|Cowgol}}== |
=={{header|Cowgol}}== |
||
< |
<syntaxhighlight lang="cowgol">include "cowgol.coh"; |
||
const PRIME_LIMIT := 999; |
const PRIME_LIMIT := 999; |
||
Line 424: | Line 424: | ||
n := n + 1; |
n := n + 1; |
||
end loop; |
end loop; |
||
print_nl();</ |
print_nl();</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
||
Line 431: | Line 431: | ||
{{libheader| PrimTrial}} |
{{libheader| PrimTrial}} |
||
{{Trans|Ring}} |
{{Trans|Ring}} |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
program Find_prime_n_for_that_reversed_n_is_also_prime; |
program Find_prime_n_for_that_reversed_n_is_also_prime; |
||
Line 479: | Line 479: | ||
Writeln('done...'); |
Writeln('done...'); |
||
readln; |
readln; |
||
end.</ |
end.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>working... |
<pre>working... |
||
Line 493: | Line 493: | ||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |
||
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)] |
||
< |
<syntaxhighlight lang="fsharp"> |
||
// Reversible Primes. Nigel Galloway: March 22nd., 2021 |
// Reversible Primes. Nigel Galloway: March 22nd., 2021 |
||
let emirp2=let rec fN g=function |0->g |n->fN(g*10+n%10)(n/10) in primes32()|>Seq.filter(fN 0>>isPrime) |
let emirp2=let rec fN g=function |0->g |n->fN(g*10+n%10)(n/10) in primes32()|>Seq.filter(fN 0>>isPrime) |
||
emirp2|>Seq.takeWhile((>)500)|>Seq.iter(printf "%d "); printfn "" |
emirp2|>Seq.takeWhile((>)500)|>Seq.iter(printf "%d "); printfn "" |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 504: | Line 504: | ||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
{{works with|Factor|0.99 2021-02-05}} |
{{works with|Factor|0.99 2021-02-05}} |
||
< |
<syntaxhighlight lang="factor">USING: formatting grouping io kernel math math.primes sequences ; |
||
: reverse-digits ( 123 -- 321 ) |
: reverse-digits ( 123 -- 321 ) |
||
Line 511: | Line 511: | ||
499 primes-upto [ reverse-digits prime? ] filter |
499 primes-upto [ reverse-digits prime? ] filter |
||
dup length "Found %d reverse primes < 500.\n\n" printf |
dup length "Found %d reverse primes < 500.\n\n" printf |
||
10 group [ [ "%4d" printf ] each nl ] each nl</ |
10 group [ [ "%4d" printf ] each nl ] each nl</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 524: | Line 524: | ||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
{{works with|Gforth}} |
{{works with|Gforth}} |
||
< |
<syntaxhighlight lang="forth">: prime? ( n -- ? ) here + c@ 0= ; |
||
: not-prime! ( n -- ) here + 1 swap c! ; |
: not-prime! ( n -- ) here + 1 swap c! ; |
||
Line 565: | Line 565: | ||
main |
main |
||
bye</ |
bye</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 578: | Line 578: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
Use one of the primality testing algorithms as an include as I can't be bothered putting these in all the time. |
Use one of the primality testing algorithms as an include as I can't be bothered putting these in all the time. |
||
< |
<syntaxhighlight lang="freebasic">#include "isprime.bas" |
||
function isbackprime( byval n as integer ) as boolean |
function isbackprime( byval n as integer ) as boolean |
||
Line 594: | Line 594: | ||
if isbackprime(n) then print n;" "; |
if isbackprime(n) then print n;" "; |
||
next n |
next n |
||
print</ |
print</syntaxhighlight> |
||
{{out}}<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
{{out}}<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
||
=={{header|Frink}}== |
=={{header|Frink}}== |
||
< |
<syntaxhighlight lang="frink">select[primes[2,500], {|n| isPrime[parseInt[join["", reverse[integerDigits[n]]]]]}]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 605: | Line 605: | ||
=={{header|Go}}== |
=={{header|Go}}== |
||
< |
<syntaxhighlight lang="go">package main |
||
import "fmt" |
import "fmt" |
||
Line 662: | Line 662: | ||
} |
} |
||
fmt.Printf("\n\n%d such primes found.\n", len(reversedPrimes)) |
fmt.Printf("\n\n%d such primes found.\n", len(reversedPrimes)) |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 676: | Line 676: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">import Data.List (intercalate, transpose) |
||
import Data.List.Split (chunksOf) |
import Data.List.Split (chunksOf) |
||
import Data.Numbers.Primes (isPrime, primes) |
import Data.Numbers.Primes (isPrime, primes) |
||
Line 713: | Line 713: | ||
widths |
widths |
||
) |
) |
||
rows</ |
rows</syntaxhighlight> |
||
{{Out}} |
{{Out}} |
||
<pre>Reversible primes below 500: |
<pre>Reversible primes below 500: |
||
Line 727: | Line 727: | ||
Using the definition of is_prime at [[Erd%C5%91s-primes#jq]]: |
Using the definition of is_prime at [[Erd%C5%91s-primes#jq]]: |
||
< |
<syntaxhighlight lang="jq"># Generate a stream of reversible primes. |
||
# If . is null the stream is unbounded; |
# If . is null the stream is unbounded; |
||
# otherwise only integers less than . are considered. |
# otherwise only integers less than . are considered. |
||
Line 737: | Line 737: | ||
"Primes under 500 which are also primes when the digits are reversed:", |
"Primes under 500 which are also primes when the digits are reversed:", |
||
(500 | reversible_primes)</ |
(500 | reversible_primes)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 778: | Line 778: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
< |
<syntaxhighlight lang="julia">using Primes |
||
let |
let |
||
Line 793: | Line 793: | ||
println("Total found: $pcount") |
println("Total found: $pcount") |
||
end |
end |
||
</ |
</syntaxhighlight>{{out}} |
||
<pre> |
<pre> |
||
Reversible primes between 0 and 500: |
Reversible primes between 0 and 500: |
||
Line 802: | Line 802: | ||
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica">Select[Range[499], PrimeQ[#] \[And] PrimeQ[IntegerReverse[#]] &]</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>{2,3,5,7,11,13,17,31,37,71,73,79,97,101,107,113,131,149,151,157,167,179,181,191,199,311,313,337,347,353,359,373,383,389}</pre> |
<pre>{2,3,5,7,11,13,17,31,37,71,73,79,97,101,107,113,131,149,151,157,167,179,181,191,199,311,313,337,347,353,359,373,383,389}</pre> |
||
=={{header|MAD}}== |
=={{header|MAD}}== |
||
< |
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER |
||
BOOLEAN PRIME |
BOOLEAN PRIME |
||
DIMENSION PRIME(1000) |
DIMENSION PRIME(1000) |
||
Line 834: | Line 834: | ||
PRINT FORMAT FMT,N |
PRINT FORMAT FMT,N |
||
TEST CONTINUE |
TEST CONTINUE |
||
END OF PROGRAM</ |
END OF PROGRAM</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'> 2 |
<pre style='height:50ex;'> 2 |
||
Line 872: | Line 872: | ||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
< |
<syntaxhighlight lang="modula2">MODULE ReversePrime; |
||
FROM InOut IMPORT WriteCard, WriteLn; |
FROM InOut IMPORT WriteCard, WriteLn; |
||
Line 922: | Line 922: | ||
END; |
END; |
||
WriteLn(); |
WriteLn(); |
||
END ReversePrime.</ |
END ReversePrime.</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 2 3 5 7 11 13 17 31 |
<pre> 2 3 5 7 11 13 17 31 |
||
Line 932: | Line 932: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
< |
<syntaxhighlight lang="nim">import math, strutils |
||
const |
const |
||
Line 961: | Line 961: | ||
stdout.write ($n).align(3) |
stdout.write ($n).align(3) |
||
stdout.write if (i + 1) mod 10 == 0: '\n' else: ' ' |
stdout.write if (i + 1) mod 10 == 0: '\n' else: ' ' |
||
echo()</ |
echo()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 971: | Line 971: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
{{libheader|ntheory}} |
{{libheader|ntheory}} |
||
< |
<syntaxhighlight lang="perl">use strict; |
||
use warnings; |
use warnings; |
||
use List::Util 'max'; |
use List::Util 'max'; |
||
Line 984: | Line 984: | ||
my($limit, @rp) = 500; |
my($limit, @rp) = 500; |
||
is_prime($_) and is_prime(reverse $_) and push @rp, $_ for 1..$limit; |
is_prime($_) and is_prime(reverse $_) and push @rp, $_ for 1..$limit; |
||
print @rp . " reversible primes < $limit:\n" . pp(@rp);</ |
print @rp . " reversible primes < $limit:\n" . pp(@rp);</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>34 reversible primes < 500: |
<pre>34 reversible primes < 500: |
||
Line 992: | Line 992: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--< |
<!--<syntaxhighlight lang="phix">(phixonline)--> |
||
<span style="color: #008080;">function</span> <span style="color: #000000;">rp</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">to_integer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">))))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
<span style="color: #008080;">function</span> <span style="color: #000000;">rp</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">is_prime</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">to_integer</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">sprint</span><span style="color: #0000FF;">(</span><span style="color: #000000;">p</span><span style="color: #0000FF;">))))</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span> |
||
<span style="color: #008080;">procedure</span> <span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">args</span><span style="color: #0000FF;">)</span> |
<span style="color: #008080;">procedure</span> <span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">args</span><span style="color: #0000FF;">)</span> |
||
Line 1,001: | Line 1,001: | ||
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span> |
||
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">({{</span><span style="color: #000000;">500</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":\n%s"</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":\n%s"</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">10000</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"."</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">10_000_000</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"."</span><span style="color: #0000FF;">}},</span><span style="color: #000000;">test</span><span style="color: #0000FF;">)</span> |
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">({{</span><span style="color: #000000;">500</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":\n%s"</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">1000</span><span style="color: #0000FF;">,</span><span style="color: #008000;">":\n%s"</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">10000</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"."</span><span style="color: #0000FF;">},{</span><span style="color: #000000;">10_000_000</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"."</span><span style="color: #0000FF;">}},</span><span style="color: #000000;">test</span><span style="color: #0000FF;">)</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,018: | Line 1,018: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
< |
<syntaxhighlight lang="python">#!/usr/bin/python |
||
def isPrime(n): |
def isPrime(n): |
||
Line 1,039: | Line 1,039: | ||
for n in range(2, 499): |
for n in range(2, 499): |
||
if isBackPrime(n): |
if isBackPrime(n): |
||
print(n, end=' ');</ |
print(n, end=' ');</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre> |
||
Line 1,045: | Line 1,045: | ||
=={{header|PILOT}}== |
=={{header|PILOT}}== |
||
< |
<syntaxhighlight lang="pilot">C :n=1 |
||
*number |
*number |
||
C :p=n |
C :p=n |
||
Line 1,081: | Line 1,081: | ||
J (i<p/2):*div |
J (i<p/2):*div |
||
C :pr=1 |
C :pr=1 |
||
E :</ |
E :</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre style='height:50ex;'>2 |
<pre style='height:50ex;'>2 |
||
Line 1,119: | Line 1,119: | ||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
< |
<syntaxhighlight lang="pli">reversePrimes: procedure options(main); |
||
declare prime(1:999) bit; |
declare prime(1:999) bit; |
||
Line 1,153: | Line 1,153: | ||
put skip list('Reverse primes found:',found); |
put skip list('Reverse primes found:',found); |
||
end reversePrimes;</ |
end reversePrimes;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> 2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 |
<pre> 2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 |
||
Line 1,163: | Line 1,163: | ||
<code>eratosthenes</code> and <code>isprime</code> are defined at [[Sieve of Eratosthenes#Quackery]]. |
<code>eratosthenes</code> and <code>isprime</code> are defined at [[Sieve of Eratosthenes#Quackery]]. |
||
< |
<syntaxhighlight lang="quackery"> 1000 eratosthenes |
||
[ number$ reverse $->n drop ] is revnum ( n --> n ) |
[ number$ reverse $->n drop ] is revnum ( n --> n ) |
||
Line 1,175: | Line 1,175: | ||
[ i^ join ] ] |
[ i^ join ] ] |
||
witheach [ number$ nested join ] |
witheach [ number$ nested join ] |
||
60 wrap$</ |
60 wrap$</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,184: | Line 1,184: | ||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang |
<syntaxhighlight lang="raku" line>unit sub MAIN ($limit = 500); |
||
say "{+$_} reversible primes < $limit:\n{$_».fmt("%" ~ $limit.chars ~ "d").batch(10).join("\n")}", |
say "{+$_} reversible primes < $limit:\n{$_».fmt("%" ~ $limit.chars ~ "d").batch(10).join("\n")}", |
||
with ^$limit .grep: { .is-prime and .flip.is-prime }</ |
with ^$limit .grep: { .is-prime and .flip.is-prime }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre>34 reversible primes < 500: |
<pre>34 reversible primes < 500: |
||
Line 1,195: | Line 1,195: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
< |
<syntaxhighlight lang="rexx">/*REXX program counts/displays the number of reversed primes under a specified number N.*/ |
||
parse arg n cols . /*get optional number of primes to find*/ |
parse arg n cols . /*get optional number of primes to find*/ |
||
if n=='' | n=="," then n= 500 /*Not specified? Then assume default.*/ |
if n=='' | n=="," then n= 500 /*Not specified? Then assume default.*/ |
||
Line 1,234: | Line 1,234: | ||
#= # + 1; @.#= j; !.j= 1 /*bump prime count; assign prime & flag*/ |
#= # + 1; @.#= j; !.j= 1 /*bump prime count; assign prime & flag*/ |
||
end /*j*/ |
end /*j*/ |
||
return</ |
return</syntaxhighlight> |
||
{{out|output|text= when using the default inputs:}} |
{{out|output|text= when using the default inputs:}} |
||
<pre> |
<pre> |
||
Line 1,253: | Line 1,253: | ||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring"> |
||
load "stdlib.ring" |
load "stdlib.ring" |
||
Line 1,281: | Line 1,281: | ||
see nl + "found " + num + " primes" + nl |
see nl + "found " + num + " primes" + nl |
||
see "done..." + nl |
see "done..." + nl |
||
</syntaxhighlight> |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,294: | Line 1,294: | ||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i"; |
||
const func boolean: isPrime (in integer: number) is func |
const func boolean: isPrime (in integer: number) is func |
||
Line 1,341: | Line 1,341: | ||
writeln; |
writeln; |
||
writeln("Found " <& count <& " reverse primes < 500."); |
writeln("Found " <& count <& " reverse primes < 500."); |
||
end func;</ |
end func;</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,349: | Line 1,349: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
< |
<syntaxhighlight lang="ruby">say primes(500).grep { .reverse.is_prime }</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 1,359: | Line 1,359: | ||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
< |
<syntaxhighlight lang="ecmascript">import "/math" for Int |
||
import "/fmt" for Fmt |
import "/fmt" for Fmt |
||
import "/seq" for Lst |
import "/seq" for Lst |
||
Line 1,379: | Line 1,379: | ||
System.print("Primes under 500 which are also primes when the digits are reversed:") |
System.print("Primes under 500 which are also primes when the digits are reversed:") |
||
for (chunk in Lst.chunks(reversedPrimes, 17)) Fmt.print("$3d", chunk) |
for (chunk in Lst.chunks(reversedPrimes, 17)) Fmt.print("$3d", chunk) |
||
System.print("\n%(reversedPrimes.count) such primes found.")</ |
System.print("\n%(reversedPrimes.count) such primes found.")</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,391: | Line 1,391: | ||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is a prime number |
||
int N, I; |
int N, I; |
||
[if N <= 1 then return false; |
[if N <= 1 then return false; |
||
Line 1,421: | Line 1,421: | ||
IntOut(0, Count); |
IntOut(0, Count); |
||
Text(0, " reversible primes found."); |
Text(0, " reversible primes found."); |
||
]</ |
]</syntaxhighlight> |
||
{{out}} |
{{out}} |