Palindromic primes in base 16: Difference between revisions

m
(Added Algol 68)
m (→‎{{header|Wren}}: Minor tidy)
(30 intermediate revisions by 25 users not shown)
Line 4:
Find palindromic primes &nbsp; '''n''' &nbsp; in base 16, &nbsp; where &nbsp; '''n &nbsp; &lt; &nbsp; 500<sub>10</sub>'''
<br><br>
 
=={{header|11l}}==
<syntaxhighlight lang="11l">F is_prime(a)
I a == 2
R 1B
I a < 2 | a % 2 == 0
R 0B
L(i) (3 .. Int(sqrt(a))).step(2)
I a % i == 0
R 0B
R 1B
 
L(n) 500
V h = hex(n)
I h == reversed(h) & is_prime(n)
print(h, end' ‘ ’)
print()</syntaxhighlight>
 
{{out}}
<pre>
2 3 5 7 B D 11 101 151 161 191 1B1 1C1
</pre>
 
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<syntaxhighlight lang="action!">INCLUDE "H6:SIEVE.ACT"
 
BYTE FUNC Palindrome(CHAR ARRAY s)
BYTE l,r
 
l=1 r=s(0)
WHILE l<r
DO
IF s(l)#s(r) THEN RETURN (0) FI
l==+1 r==-1
OD
RETURN (1)
 
PROC IntToHex(INT i CHAR ARRAY hex)
CHAR ARRAY digits="0123456789ABCDEF"
BYTE d
 
hex(0)=0
WHILE i#0
DO
d=i MOD 16
hex(0)==+1
hex(hex(0))=digits(d+1)
i==/16
OD
RETURN
 
BYTE Func IsPalindromicPrime(INT i CHAR ARRAY hex
BYTE ARRAY primes)
 
BYTE d
INT rev,tmp
 
IF primes(i)=0 THEN
RETURN (0)
FI
 
IntToHex(i,hex)
IF Palindrome(hex) THEN
RETURN (1)
FI
RETURN (0)
 
PROC Main()
DEFINE MAX="499"
BYTE ARRAY primes(MAX+1)
INT i,count=[0]
CHAR ARRAY hex(5)
 
Put(125) PutE() ;clear the screen
Sieve(primes,MAX+1)
FOR i=2 TO MAX
DO
IF IsPalindromicPrime(i,hex,primes) THEN
Print(hex) Put(32)
count==+1
FI
OD
PrintF("%EThere are %I palindromic primes",count)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Palindromic_primes_in_base_16.png Screenshot from Atari 8-bit computer]
<pre>
2 3 5 7 B D 11 101 151 161 191 1B1 1C1
 
There are 13 palindromic primes
</pre>
 
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<lang algol68>BEGIN # find primes that are palendromic in base 16 #
<syntaxhighlight lang="algol68">BEGIN # find primes that are palendromic in base 16 #
INT max prime = 499;
# sieve the primes to max prime499 #
PR read "primes.incl.a68" PR
[ 1 : max prime ]BOOL prime;
prime[ 1 ] := FALSE;BOOL prime[ 2= ] :=PRIMESIEVE TRUE499;
FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE OD;
FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD;
FOR i FROM 3 BY 2 TO ENTIER sqrt( max prime ) DO
IF prime[ i ] THEN FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD FI
OD;
# returns an array of the digits of n in the specified base #
PRIO DIGITS = 9;
Line 46 ⟶ 133:
# print the palendromic primes in the base 16 #
STRING base digits = "0123456789ABCDEF";
FOR n TO maxUPB prime DO
IF prime[ n ] THEN
# have a prime #
Line 58 ⟶ 145:
FI
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 64 ⟶ 151:
</pre>
 
=={{header|AppleScript}}==
 
<syntaxhighlight lang="applescript">on isPrime(n)
if ((n < 4) or (n is 5)) then return (n > 1)
if ((n mod 2 = 0) or (n mod 3 = 0) or (n mod 5 = 0)) then return false
repeat with i from 7 to (n ^ 0.5) div 1 by 30
if ((n mod i = 0) or (n mod (i + 4) = 0) or (n mod (i + 6) = 0) or ¬
(n mod (i + 10) = 0) or (n mod (i + 12) = 0) or (n mod (i + 16) = 0) or ¬
(n mod (i + 22) = 0) or (n mod (i + 24) = 0)) then return false
end repeat
return true
end isPrime
 
on task()
set digits to "0123456789ABCDEF"'s characters
set output to {"2"} -- Take "2" as read.
repeat with n from 3 to 499 by 2 -- All other primes are odd.
if (isPrime(n)) then
-- Only the number's hex digit /values/ are needed for testing.
set vals to {}
repeat until (n = 0)
set vals's beginning to n mod 16
set n to n div 16
end repeat
-- If they're palindromic, build a text representation and append this to the output.
if (vals = vals's reverse) then
set hex to digits's item ((vals's beginning) + 1)
repeat with i from 2 to (count vals)
set hex to hex & digits's item ((vals's item i) + 1)
end repeat
set output's end to hex
end if
end if
end repeat
return output
end task
 
task()</syntaxhighlight>
 
{{output}}
<syntaxhighlight lang="applescript">{"2", "3", "5", "7", "B", "D", "11", "101", "151", "161", "191", "1B1", "1C1"}</syntaxhighlight>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="rebol">palindrome?: function [a][
and? -> prime? a
-> equal? digits.base:16 a reverse digits.base:16 a
]
 
print map select 1..500 => palindrome? 'x -> upper as.hex x</syntaxhighlight>
 
{{out}}
 
<pre>2 3 5 7 B D 11 101 151 161 191 1B1 1C1</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f PALINDROMIC_PRIMES_IN_BASE_16.AWK
BEGIN {
start = 1
stop = 499
for (i=start; i<=stop; i++) {
hex = sprintf("%X",i)
if (is_prime(i) && hex == reverse(hex)) {
printf("%4s%1s",hex,++count%10?"":"\n")
}
}
printf("\nPalindromic primes %d-%d: %d\n",start,stop,count)
exit(0)
}
function is_prime(x, i) {
if (x <= 1) {
return(0)
}
for (i=2; i<=int(sqrt(x)); i++) {
if (x % i == 0) {
return(0)
}
}
return(1)
}
function reverse(str, i,rts) {
for (i=length(str); i>=1; i--) {
rts = rts substr(str,i,1)
}
return(rts)
}
</syntaxhighlight>
{{out}}
<pre>
2 3 5 7 B D 11 101 151 161
191 1B1 1C1
Palindromic primes 1-499: 13
</pre>
 
=={{header|C++}}==
See [[Palindromic primes#C.2B.2B|C++ solution for task 'Palindromic Primes']].
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
function IsPrime(N: int64): boolean;
{Fast, optimised prime test}
var I,Stop: int64;
begin
if (N = 2) or (N=3) then Result:=true
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false
else
begin
I:=5;
Stop:=Trunc(sqrt(N+0.0));
Result:=False;
while I<=Stop do
begin
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit;
Inc(I,6);
end;
Result:=True;
end;
end;
 
 
 
 
function IsPalindrome(N, Base: integer): boolean;
{Test if number is the same forward or backward}
{For a specific Radix}
var S1,S2: string;
begin
S1:=GetRadixString(N,Base);
S2:=ReverseString(S1);
Result:=S1=S2;
end;
 
 
 
procedure ShowPalindromePrimes16(Memo: TMemo);
var I: integer;
var Cnt: integer;
var S: string;
begin
Cnt:=0;
for I:=1 to 1000-1 do
if IsPrime(I) then
if IsPalindrome(I,16) then
begin
Inc(Cnt);
S:=S+Format('%4X',[I]);
If (Cnt mod 5)=0 then S:=S+CRLF;
end;
Memo.Lines.Add(S);
Memo.Lines.Add('Count='+IntToStr(Cnt));
end;
 
</syntaxhighlight>
{{out}}
<pre>
2 3 5 7 B
D 11 101 151 161
191 1B1 1C1 313 373
3B3
Count=16
Elapsed Time: 2.116 ms.
 
</pre>
 
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<syntaxhighlight lang="fsharp">
let rec fN g=[yield g%16; if g>15 then yield! fN(g/16)]
primes32()|>Seq.takeWhile((>)500)|>Seq.filter(fun g->let g=fN g in List.rev g=g)|>Seq.iter(printf "%0x "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
2 3 5 7 b d 11 101 151 161 191 1b1 1c1
</pre>
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: kernel math.parser math.primes prettyprint sequences
sequences.extras ;
 
500 primes-upto [ >hex ] [ dup reverse = ] map-filter .</langsyntaxhighlight>
{{out}}
<pre>
Line 87 ⟶ 356:
}
</pre>
 
 
=={{header|FreeBASIC}}==
<syntaxhighlight lang="freebasic">
Function isprime(num As Ulongint) As Boolean
For i As Integer = 2 To Sqr(num)
If (num Mod i = 0) Then Return False
Next i
Return True
End Function
 
Function reverse(Byval text As String) As String
Dim As String text2 = text
Dim As Integer x, lt = Len(text)
For x = 0 To lt Shr 1 - 1
Swap text2[x], text2[lt - x - 1]
Next x
Return text2
End Function
 
Dim As Integer inicio = 2, final = 499, cont = 0
 
For i As Integer = inicio To final
Dim As String hexi = Str(Hex(i))
If isprime(i) = True And hexi = reverse(hexi) Then
cont += 1
Print Hex(i); " ";
End If
Next i
 
Print !"\n\nEncontrados"; cont; " primos palindrómicos entre " & inicio & " y " & final
Sleep
</syntaxhighlight>
{{out}}
<pre>2 3 5 7 B D 11 101 151 161 191 1B1 1C1
 
Encontrados 13 primos palindrómicos entre 2 y 499</pre>
 
 
=={{header|Go}}==
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 122 ⟶ 430:
}
fmt.Println("\n\nFound", count, "such primes.")
}</langsyntaxhighlight>
 
{{out}}
Line 133 ⟶ 441:
Found 13 such primes.
</pre>
 
 
=={{header|J}}==
 
<syntaxhighlight lang=J> palindromic16=: (-: |.)@hfd@>
hfd@> (#~ palindromic16) p: i. p:inv 500
2
3
5
7
b
d
11
101
151
161
191
1b1
1c1</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
This entry uses a generator that produces an unbounded stream of arrays of the form [dec, hex], where `dec` is the palindromic prime as a JSON number, and `hex` is the JSON string corresponding to its hexadecimal representation.
 
For a suitable implementation of `is_prime`, see e.g. [[Erd%C5%91s-primes#jq]].
<syntaxhighlight lang="jq">
# '''Preliminaries'''
 
def emit_until(cond; stream): label $out | stream | if cond then break $out else . end;
 
# decimal number to exploded hex array
def exploded_hex:
def stream:
recurse(if . > 0 then ./16|floor else empty end) | . % 16 ;
if . == 0 then [48]
else [stream] | reverse | .[1:]
| map(if . < 10 then 48 + . else . + 87 end)
end;
</syntaxhighlight>
'''The Task'''
<syntaxhighlight lang="jq"># Output: a stream of [decimal, hexadecimal] values
def palindromic_primes_in_base_16:
(2, (range(3; infinite; 2) | select(is_prime)))
| exploded_hex as $hex
|select( $hex | (. == reverse))
| [., ($hex|implode)] ;
 
emit_until(.[0] >= 500; palindromic_primes_in_base_16)</syntaxhighlight>
{{out}}
<pre>
[2,"2"]
[3,"3"]
[5,"5"]
[7,"7"]
[11,"b"]
[13,"d"]
[17,"11"]
[257,"101"]
[337,"151"]
[353,"161"]
[401,"191"]
[433,"1b1"]
[449,"1c1"]
</pre>
 
=={{header|Julia}}==
<syntaxhighlight lang="julia">using Primes
 
ispal(n, base) = begin dig = digits(n, base=base); dig == reverse(dig) end
 
palprimes(N, base=16) = [string(i, base=16) for i in primes(N) if ispal(i, base)]
 
foreach(s -> print(s, " "), palprimes(500, 16)) # 2 3 5 7 b d 11 101 151 161 191 1b1 1c1
</syntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Giving the base 10 numbers and the base 16 numbers:
<syntaxhighlight lang="mathematica">Select[Range[499], PrimeQ[#] \[And] PalindromeQ[IntegerDigits[#, 16]] &]
BaseForm[%, 16]</syntaxhighlight>
{{out}}
<pre>
{2, 3, 5, 7, 11, 13, 17, 257, 337, 353, 401, 433, 449}
{Subscript[2, 16],Subscript[3, 16],Subscript[5, 16],Subscript[7, 16],Subscript[b, 16],Subscript[d, 16],Subscript[11, 16],Subscript[101, 16],Subscript[151, 16],Subscript[161, 16],Subscript[191, 16],Subscript[1b1, 16],Subscript[1c1, 16]}
</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">import strformat, strutils
 
func isPalindromic(s: string): bool =
for i in 1..s.len:
if s[i-1] != s[^i]: return false
result = true
 
func isPrime(n: Natural): bool =
if n < 2: return false
if n mod 2 == 0: return n == 2
if n mod 3 == 0: return n == 3
var d = 5
while d * d <= n:
if n mod d == 0: return false
inc d, 2
if n mod d == 0: return false
inc d, 4
return true
 
 
var list: seq[string]
for n in 0..<500:
let h = &"{n:x}"
if h.isPalindromic and n.isPrime: list.add h
 
echo "Found ", list.len, " palindromic primes in base 16:"
echo list.join(" ")</syntaxhighlight>
 
{{out}}
<pre>Found 13 palindromic primes in base 16:
2 3 5 7 b d 11 101 151 161 191 1b1 1c1</pre>
 
=={{header|Perl}}==
<syntaxhighlight lang="perl"> (1 x $_ ) !~ /^(11+)\1+$/ # test if prime
and $h = sprintf "%x", $_ # convert to hex
and $h eq reverse $h # palindromic?
and print "$h " # much rejoicing
for 1..500;</syntaxhighlight>
{{out}}
<pre>1 2 3 5 7 b d 11 101 151 161 191 1b1 1c1</pre>
 
=={{header|Phix}}==
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">palindrome</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">reverse</span><span style="color: #0000FF;">(</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%x"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">palindrome</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"found %d: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">)})</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
found 13: 2 3 5 7 B D 11 101 151 161 191 1B1 1C1
</pre>
 
=={{header|Quackery}}==
 
See [[Palindromic primes#Quackery]] for rest of code. This is a trivial modification.
 
<syntaxhighlight lang="quackery">16 base put
500 times
[ i^ isprime if
[ i^ digits palindromic if
[ i^ echo sp ] ] ]
base release</syntaxhighlight>
 
{{out}}
 
<pre>2 3 5 7 B D 11 101 151 161 191 1B1 1C1</pre>
 
 
=={{header|Raku}}==
Trivial modification of [[Palindromic_primes#Raku|Palindromic primes]] task.
<syntaxhighlight lang="raku" line>say "{+$_} matching numbers:\n{.batch(10)».fmt('%3X').join: "\n"}"
given (^500).grep: { .is-prime and .base(16) eq .base(16).flip };</syntaxhighlight>
{{out}}
<pre>13 matching numbers:
2 3 5 7 B D 11 101 151 161
191 1B1 1C1</pre>
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX program finds and displays hexadecimal palindromic primes in base 16 for all N < 500. */
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 500 /*Not specified? Then use the default.*/
Line 146 ⟶ 619:
finds= 0; idx= 1 /*define # of palindromic primes & idx.*/
$= /*hex palindromic primes list (so far).*/
do j=1 for hi; if \!.j then iterate /*J (decimal) not prime? Then skip.*/ /* ◄■■■■■■■■ a filter. */
x= d2x(j); if x\==reverse(x) then iterate /*Hex value not palindromic? " " */ /* ◄■■■■■■■■ a filter. */
finds= finds + 1 /*bump the number of palindromic primes*/
if cols<0 then iterate /*Build the list (to be shown later)? */
Line 167 ⟶ 640:
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */
!.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /* " " " " flags. */
#=5; ssq.#= @.# **2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 to hip /*find odd primes from here on. */
parse var j '' -1 _; if if _==5 then iterate /*J divisible÷ by 5? (right digdigit).*/
if j//3==0 then iterate; if j// 37==0 then iterate /*" " " 3? J ÷ by 7? */
do k=5 while sq.k<=j if j// 7==0 then iterate /*" " " 7? [↓] divide by the known odd primes.*/
/* [↑] the above 3 lines saves time.*/
do k=5 while s.k<=j /* [↓] divide by the known odd primes.*/
if j // @.k == 0 then iterate j /*Is J ÷ X? Then not prime. ___ */
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; ssq.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 191 ⟶ 662:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
see "working..." + nl
see "Palindromic primes in base 16:" + nl
row = 0
decList = 0:15
baseList = ["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"]
limit = 500
 
Line 213 ⟶ 682:
see nl + "Found " + row + " palindromic primes in base 16" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 223 ⟶ 692:
Found 13 palindromic primes in base 16
done...
</pre>
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">res = Prime.each(500).filter_map do |pr|
str = pr.to_s(16)
str if str == str.reverse
end
puts res.join(", ")</syntaxhighlight>
{{out}}
<pre>2, 3, 5, 7, b, d, 11, 101, 151, 161, 191, 1b1, 1c1
</pre>
 
=={{header|Rust}}==
See [[Palindromic primes#Rust|Rust solution for task 'Palindromic Primes']].
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
 
const func boolean: isPrime (in integer: number) is func
result
var boolean: prime is FALSE;
local
var integer: upTo is 0;
var integer: testNum is 3;
begin
if number = 2 then
prime := TRUE;
elsif odd(number) and number > 2 then
upTo := sqrt(number);
while number rem testNum <> 0 and testNum <= upTo do
testNum +:= 2;
end while;
prime := testNum > upTo;
end if;
end func;
 
const proc: main is func
local
var integer: n is 0;
var string: hex is "";
begin
for n range 2 to 499 do
if isPrime(n) then
hex := n radix 16;
if hex = reverse(hex) then
write(hex <& " ");
end if;
end if;
end for;
end func;</syntaxhighlight>
{{out}}
<pre>
2 3 5 7 b d 11 101 151 161 191 1b1 1c1
</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func palindromic_primes(upto, base = 10) {
var list = []
for (var p = 2; p <= upto; p = p.next_palindrome(base)) {
list << p if p.is_prime
}
return list
}
 
var list = palindromic_primes(500, 16)
 
list.each {|p|
say "#{'%3s' % p}_10 = #{'%3s' % p.base(16)}_16"
}</syntaxhighlight>
{{out}}
<pre>
2_10 = 2_16
3_10 = 3_16
5_10 = 5_16
7_10 = 7_16
11_10 = b_16
13_10 = d_16
17_10 = 11_16
257_10 = 101_16
337_10 = 151_16
353_10 = 161_16
401_10 = 191_16
433_10 = 1b1_16
449_10 = 1c1_16
</pre>
 
Line 228 ⟶ 782:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./fmt" for Conv, Fmt
 
System.print("Primes < 500 which are palindromic in base 16:")
Line 242 ⟶ 796:
}
}
System.print("\n\nFound %(count) such primes.")</langsyntaxhighlight>
 
{{out}}
Line 252 ⟶ 806:
 
Found 13 such primes.
</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
[if N <= 1 then return false;
for I:= 2 to sqrt(N) do
if rem(N/I) = 0 then return false;
return true;
];
 
func Reverse(N, Base); \Reverse order of digits in N for given Base
int N, Base, M;
[M:= 0;
repeat N:= N/Base;
M:= M*Base + rem(0);
until N=0;
return M;
];
 
int Count, N;
[SetHexDigits(1);
Count:= 0;
for N:= 0 to 500-1 do
if IsPrime(N) & N=Reverse(N, 16) then
[HexOut(0, N);
Count:= Count+1;
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
];
CrLf(0);
IntOut(0, Count);
Text(0, " such numbers found.
");
]</syntaxhighlight>
 
{{out}}
<pre>
2 3 5 7 B D 11 101 151 161
191 1B1 1C1
13 such numbers found.
</pre>
9,482

edits