Munchausen numbers: Difference between revisions

m
→‎{{header|Pascal}}: more explanation, hopefully no obfuscation ;-)
(→‎{{header|ALGOL 68}}: Remove unnecessary test)
m (→‎{{header|Pascal}}: more explanation, hopefully no obfuscation ;-))
Line 294:
<pre>1
3435</pre>
=={{header|Pascal}}=={{works with|Free Pascal}}{{works with|Delphi}}
tried to speed things up.Only checking one arrangement of 123456789 instead of all 9! = 362880 permutations.
This ist possible, because summing up is commutative.So I only need to check, that the number and the sum of power of digits have the same amount in every possible digit.This means, that a permutation of the digits of number leads to the sum of power of digits.Therefor I need leading zero's.
<lang pascal>{$IFDEF FPC}
<lang pascal>{$IFDEF FPC}{$MODE objFPC}{$ELSE}{$APPTYPE CONSOLE}{$ENDIF}
{$ENDIF}
uses
sysutils;
Line 305 ⟶ 304:
const
base = 10;
maxDigits = base-1;// set for 32-compilation otherwise overflow.
 
var
Line 341 ⟶ 340:
else
For i := minDigit to base-1 do
// number is always the smallest arrangement of the digits leading to smallest number
IF (number+i)<= (DgtPowSum+DgtPotDgt[i]) then
IF CheckSameDigits(number+i,DgtPowSum+DgtPotDgt[i]) then
iF number+i>0 then
writeln(DgtPowSum+DgtPotDgt[i]:20Format('%*d %.*d',number+i:20);
[maxDigits,DgtPowSum+DgtPotDgt[i],maxDigits,number+i]));
end;
 
Line 368:
Munch(0,0,0,maxDigits);
writeln('Check Count ',cnt);
end.</lang>
</lang>
{{Out}}
<pre> 1 1000000001
3435 3345000003345
438579088 34578889034578889
Check Count 43758
 
real 0m0.002s</pre>
</pre>
 
=={{header|Perl 6}}==
Anonymous user