MATLAB: Creating a formula for a question

codedaily contestinteger and positivenon-zerosymbolicvariable

Hello Dear Matlab users
I need some HELP.
I saw 'a "one-a-day" journal contest' question about so called 'perfect numbers'. (I don't know exact translation of the term). The question was as following:
The Number 18432 is a number that has a feature of non-zero digit in itself,non-repeating digit, also has the ability to split into their numbers sum and products. Also it's more one digit, positive number (it has a lot). Other examples are 12,432,3168,13248 and they go until the number reaches total 21 piece. Well the question asks:
what is the smallest one, greater than 18432??
I thought that I could write a m.file to answer this question.
I've tried to initiate the m.file as following
if true
A=sym('A%d%d',[1,5],'integer&&positive');
sum(A)
assumptions(A);
end
I know it needs a lot of work, but a general idea might spark some thoughts to reconfigure the necessary function.
Thank you already for your consideration.

Best Answer

So, you want to find a (nonrepeating) sequence of decimal digits, a vector D taken from the set [1:9], that have the two properties that
1. The product of the digits divides the number when viewed as an integer, thus converted to base 10.
2. The sum of the digits also divides the number when viewed as an integer.
N = (18434:99999)';D = dec2base(N,10) - '0';
ind = find((mod(N,sum(D,2)) == 0) & (mod(N,prod(D,2)) == 0) & all(D > 0,2) & all(diff(D,[],2) ~= 0,2));
N(ind)
ans =
21216
21312
21672
24192
24912
26136
26712
27216
31212
32616
32832
34272
35175
41232
41616
42192
42624
42912
43632
51975
61824
71316
81216
83232
Seems a bit trivial. Unless by non-repeating digit, you mean that no single digit can appear more than once in the entire number. In that case...
ind = find((mod(N,sum(D,2)) == 0) & (mod(N,prod(D,2)) == 0) & all(D > 0,2) & all(diff(D,[],2) ~= 0,2) & all(diff(sort(D,2),[],2) > 0,2))
N(ind)
ans =
61824
Still trivial.