Munchausen numbers: Difference between revisions
Content deleted Content added
{{header|Pascal}} |
m →{{header|Pascal}}: failure found wrong numbers in const DgtPotDgt, now calculating even 438579088 in an blink of an eye--- |
||
Line 284:
3435</pre>
=={{header|Pascal}}==
tried to speed things up.Only checking one arrangement of
<lang pascal>{$IFDEF FPC}▼
▲<lang pascal>
{$MODE objFPC}
{$ENDIF}
Line 296 ⟶ 294:
const
base = 10;
maxDigits =
// digit ^ digit ,special case 0^0 here 0 ▼
DgtPotDgt : array[0..base-1] of LongWord =▼
var
cnt: NativeUint;
Line 326 ⟶ 323:
inc(cnt);
number := number*base;
IF digits >
For i := minDigit to base-1 do
▲ Begin
Munch(number+i,DgtPowSum+DgtPotDgt[i],i,digits-1);
else
For i := minDigit to base-1 do
// number is always the smallest arrangement of the digits
Begin▼
IF (number+i)<=
Begin▼
▲ IF CheckSameDigits(number+i,DgtPowSum+DgtPotDgt[i]) then
writeln(DgtPowSum+DgtPotDgt[i]:20,number+i:20);
end;
end; ▼
procedure InitDgtPotDgt;
end; ▼
var
i,k,dgtpow: NativeUint;
Begin
DgtPotDgt[0]:= 0;
For i := 1 to Base-1 do
dgtpow := i;
dgtpow := dgtpow*i;
DgtPotDgt[i] := dgtpow;
▲end;
begin
cnt := 0;
InitDgtPotDgt;
Munch(0,0,0,
writeln('Check Count ',cnt);
end.</lang>
Line 352 ⟶ 361:
<pre> 1 1
3435 3345
438579088 34578889
Check Count
▲real 0m0.000s</pre>
=={{header|Perl 6}}==
<lang perl6>sub is_munchausen ( Int $n ) {
|