Palindromic primes in base 16: Difference between revisions

no edit summary
No edit summary
Line 250:
=={{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#}}==
465

edits