Munchausen numbers: Difference between revisions
→{{header|ALGOL 68}}
Line 56:
Alternative that finds all 4 Munchausen numbers. As noted by the Pascal sample, we only need to consider one arrangement of the digits of each number (e.g. we only need to consider 3345, not 3435, 3453, etc.). This also relies on the non-standard 0^0 = 0.
<lang algol68># Find all Munchausen numbers - note 11*(9^9) has
# Munchausen numbers with 11+ digits #
# table of Nth powers - note 0^0 is 0 for Munchausen numbers, not 1 #
Line 64:
[ 0 : 9 ]INT d count := z count;
# as the digit
# consider one arrangement of each possible combination of digits #
FOR d1 FROM 0 TO 9 DO
Line 81:
digit power sum +:= nth power[ d7 ] + nth power[ d8 ];
digit power sum +:= nth power[ d9 ] + nth power[ da ];
# count the occurrences of each digit (including leading zeros #
d count := z count;
d count[ d1 ] +:= 1; d count[ d2 ] +:= 1; d count[ d3 ] +:= 1;
Line 86 ⟶ 87:
d count[ d7 ] +:= 1; d count[ d8 ] +:= 1; d count[ d9 ] +:= 1;
d count[ da ] +:= 1;
# have a Munchausen number #
LONG INT number := digit power sum;
INT leading zeros := 10;
WHILE number > 0 DO
d count[ SHORTEN ( number MOD 10 ) ] -:= 1;
|