A Factorion is a number that equals the sum of the factorials of its decimal digits, e.g. 145 is a factorion because 1! + 4! + 5! = 1 + 24 + 120 = 145.
There are only 4 base 10 Factorions. A prior Perplexus problem,
Factorials & factorions, asked you to find the fourth and largest one.
A "Factoritwo" is a base 10 integer such that the integer is equal to the sum of factorials of one greater than each digit.
For example, if we were checking 145 we calculate 2! + 5! + 6! which of course is not 145.
What is the smallest Factoritwo?
The short story: As mentioned below, the smallest (and only) factoritwo is 3679464.
for n=1000000:3000000
s=num2str(n);
tot=0;
for i=1:length(s)
tot=tot+factorial(str2double(s(i))+1);
end
if tot==n
disp(n);
end
end
found nothing, so, figuring it needed to go higher, I switched strategies. Instead of testing each number, I'd test combinations of digits. That would go faster, as 213457 and 719 others would be in the batch considered as 123457 where the total 2+6+24+120+720+40320 = 41192 does not consist of those digits. The sum of the incremented factorials of those digits would be tested to see if it matched the numbers. I'd allow for eight-digit numbers:
for i=1:10
f(i)=factorial(i);
end
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];
tot=0;
for i=1:length(dig)
tot=tot+f(str2double(dig(i))+1);
end
tt=char(string(tot));
if isequal(sort(tt),sort(dig))
disp(tt);
end
end
end
end
end
end
end
end
end
end
end
finds
3679464
24
5040
40320
3628800
120
5040
120
-------
3679464
found when testing the combination 3, 4, 4, 6, 6, 7, 9.
I had really only needed to go another million in the original program, which would have been quicker than writing a new, faster, program.
Also, I think 3679464 is the only such number. All 8-and-fewer-digit possibilities have been tested (that's one advantage of the new program). The most that a 9-digit number could add to would be 9*(10!) = 32659200, which has only 8 digits, so higher than 8 digits would be impossible..
|
Posted by Charlie
on 2021-12-16 15:43:11 |