An Armstrong number is a positive integer that equals the sum of M-th powers of their digits when the number is M-digit long.
153 is an Armstrong number, since: 1
3+5
3+3
3=153.
Sloane's A005188 has an article on this, in which inter-alia it is mentioned that the sequence of Armstrong numbers terminates at the 88th term.
An
Armstwo number is a base ten, M-digit long positive integer which is equal to the sum of M-th powers of
one greater than each of the digits.
For example, if we check for 153, we find that:
2
3+6
3+4
3= 288, which is NOT equal to 153.
Determine the smallest Armstwo number.
**** Heartfelt thanks to Larry for inspiring this puzzle.
A small modification of the factoritwo program:
clearvars
for zeros=0:8
z=repmat('0',1,zeros);
for ones=0:8-zeros
o=repmat('1',1,ones);
for twos=0:8-zeros-ones
t=repmat('2',1,twos);
for threes=0:8-zeros-ones-twos
th=repmat('3',1,threes);
for fours=0:8-zeros-ones-twos-threes
fo=repmat('4',1,fours);
for fives=0:8-zeros-ones-twos-threes-fours
fi=repmat('5',1,fives) ;
for sixes=0:8-zeros-ones-twos-threes-fours-fives
sx=repmat('6',1,sixes);
for sevens=0:8-zeros-ones-twos-threes-fours-fives-sixes
sv=repmat('7',1,sevens);
for eights=0:8-zeros-ones-twos-threes-fours-fives-sixes-sevens
e=repmat('8',1,eights);
for nines=0:8-zeros-ones-twos-threes-fours-fives-sixes-sevens-eights
ni=repmat('9',1,nines);
dig=[z o t th fo fi sx sv e ni];
if length(dig)>0
M=length(dig);
else
M=0;
end
tot=0;
for i=1:length(dig)
tot=tot+(str2double(dig(i))+1)^M;
end
tt=char(string(tot));
if isequal(sort(tt),sort(dig))
disp(tt);
end
end
end
end
end
end
end
end
end
end
end
checks up to 8-digit numbers but finds only 3-digit numbers:
251
141
560
The smallest is 141. 251 was found before it, as combinations with only one 1 were found before those with two 1's (within the case that no zeros were used).
|
Posted by Charlie
on 2021-12-27 11:31:01 |