Anonymous user
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}{$MODE objFPC}{$ELSE}{$APPTYPE CONSOLE}{$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
//
IF (number+i)<= (DgtPowSum+DgtPotDgt[i]) then
IF CheckSameDigits(number+i,DgtPowSum+DgtPotDgt[i]) then
iF number+i>0 then
writeln(
[maxDigits,DgtPowSum+DgtPotDgt[i],maxDigits,number+i]));
end;
Line 368:
Munch(0,0,0,maxDigits);
writeln('Check Count ',cnt);
end.
</lang>
{{Out}}
<pre>
Check Count 43758
real 0m0.002s
</pre>
=={{header|Perl 6}}==
|