Upside-down numbers: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: use 12px to prevent line break) |
No edit summary |
||
Line 259: | Line 259: | ||
50,000,000th : 9,285,587,463,255,281 |
50,000,000th : 9,285,587,463,255,281 |
||
</pre> |
</pre> |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|SysUtils,StdCtrls}} |
|||
<syntaxhighlight lang="Delphi"> |
|||
function IsUpsideDown(N: integer): boolean; |
|||
{Test if N is upsidedown number} |
|||
var I,J: integer; |
|||
var IA: TIntegerDynArray; |
|||
begin |
|||
Result:=False; |
|||
{Get all digits in the number} |
|||
GetDigits(N,IA); |
|||
for I:=0 to Length(IA) div 2 do |
|||
begin |
|||
{Index to right side of number} |
|||
J:=High(IA)-I; |
|||
{do left and right side add up to 10?} |
|||
if IA[J]+IA[I]<>10 then exit; |
|||
{No zeros allowed} |
|||
if (IA[J]=0) or (IA[I]=0) then exit; |
|||
end; |
|||
Result:=True; |
|||
end; |
|||
procedure ShowUpsideDownNumbers(Memo: TMemo); |
|||
var I,J,K: integer; |
|||
var Cnt: integer; |
|||
var S: string; |
|||
begin |
|||
Cnt:=0; |
|||
S:=''; |
|||
{Show first 50 upside down numbers} |
|||
for I:=5 to high(integer) do |
|||
if IsUpsideDown(I) then |
|||
begin |
|||
Inc(Cnt); |
|||
S:=S+Format('%5d',[I]); |
|||
if (Cnt mod 10)=0 then S:=S+CRLF; |
|||
if Cnt=50 then break; |
|||
end; |
|||
Memo.Lines.Add(S); |
|||
{Show 500th, and 5,000th } |
|||
for I:=I to high(integer) do |
|||
if IsUpsideDown(I) then |
|||
begin |
|||
Inc(Cnt); |
|||
case Cnt of |
|||
500: Memo.Lines.Add(Format(' 500th Upsidedown = %10.0n',[I+0.0])); |
|||
5000: Memo.Lines.Add(Format('5,000th Upsidedown = %10.0n',[I+0.0])); |
|||
end; |
|||
if Cnt>5000 then break; |
|||
end; |
|||
end; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
5 19 28 37 46 55 64 73 82 91 |
|||
159 258 357 456 555 654 753 852 951 1199 |
|||
1289 1379 1469 1559 1649 1739 1829 1919 2198 2288 |
|||
2378 2468 2558 2648 2738 2828 2918 3197 3287 3377 |
|||
3467 3557 3647 3737 3827 3917 4196 4286 4376 4466 |
|||
500th Upsidedown = 493,716 |
|||
5,000th Upsidedown = 56,537,545 |
|||
Elapsed Time: 10.141 Sec. |
|||
</pre> |
|||
=={{header|jq}}== |
=={{header|jq}}== |