Brazilian numbers: Difference between revisions

Content added Content deleted
(→‎{{header|Vlang}}: Rename "Vlang" in "V (Vlang)")
(Added XPL0 example.)
Line 4,542: Line 4,542:
The 100,000th Brazilian number: 110468
The 100,000th Brazilian number: 110468
</pre>
</pre>

=={{header|XPL0}}==
{{trans|C}}
<syntaxhighlight lang "XPL0">func SameDigits(N, B);
int N, B, F;
[F:= rem(N/B);
N:= N/B;
while N > 0 do
[if rem(N/B) # F then return false;
N:= N/B;
];
return true;
];

func IsBrazilian(N);
int N, B;
[if N < 7 then return false;
if rem(N/2) = 0 and N >= 8 then return true;
for B:= 2 to N-2 do
if SameDigits(N, B) then return true;
return false;
];

func IsPrime(N); \Return 'true' if N is prime
int N, D;
[if N < 2 then return false;
if (N&1) = 0 then return N = 2;
if rem(N/3) = 0 then return N = 3;
D:= 5;
while D*D <= N do
[if rem(N/D) = 0 then return false;
D:= D+2;
if rem(N/D) = 0 then return false;
D:= D+4;
];
return true;
];

int I, C, N, Kinds;
[Kinds:= [" ", " odd ", " prime "];
for I:= 0 to 3-1 do
[Text(0, "First 20"); Text(0, Kinds(I));
Text(0, "Brazilian numbers:^m^j");
C:= 0; N:= 7;
loop [if IsBrazilian(N) then
[IntOut(0, N); ChOut(0, ^ );
C:= C+1;
if C = 20 then
[CrLf(0); CrLf(0); quit];
];
case I of
0: N:= N+1;
1: N:= N+2;
2: repeat N:= N+2 until IsPrime(N)
other [];
];
];
N:= 7; C:= 0;
while C < 100_000 do
[if IsBrazilian(N) then C:= C+1;
N:= N+1;
];
Text(0, "The 100,000th Brazilian number: "); IntOut(0, N-1); CrLf(0);
]</syntaxhighlight>
{{out}}
<pre>
First 20 Brazilian numbers:
7 8 10 12 13 14 15 16 18 20 21 22 24 26 27 28 30 31 32 33

First 20 odd Brazilian numbers:
7 13 15 21 27 31 33 35 39 43 45 51 55 57 63 65 69 73 75 77

First 20 prime Brazilian numbers:
7 13 31 43 73 127 157 211 241 307 421 463 601 757 1093 1123 1483 1723 2551 2801

The 100,000th Brazilian number: 110468
</pre>

=={{header|zkl}}==
=={{header|zkl}}==
<syntaxhighlight lang="zkl">fcn isBrazilian(n){
<syntaxhighlight lang="zkl">fcn isBrazilian(n){