Re: #10 Solving analytically
I'd really like to understand the thought process for obtaining those 21 numbers.
Re: #10 Solving analytically
Quote:
Originally Posted by
cbv
I'd really like to understand the thought process for obtaining those 21 numbers.
Well I tried to find a solution with pen and paper but didn't get that far really. Anyway you have this relation,
a < b < c < d
Where a, b, c and d are digits in any order in a number N. Now the problem is to find an N which equals this number M,
M = (d*1000 + c*100 + b*10 + a) - (a*1000 + b*100 + c*10 + d)
If you manipulate M algebraically you can get this,
M = (d-a)*999 + (c-b)*90
Now (d-a) and (c-b) are always positive because of a < b < c < d. That relation also says that b and c lies between a and d.
So (d-a) can vary between 8 (9-1) and 3 (because b and c lies between a and d). And with similar reasoning one can convince oneself that (c-b) can vary between 1 and (d-a)-2. In code that would be,
Code:
for (int i=3; i<=8; ++i) { // variation of (d-a)
for (int j=1; j<=i-2; ++j) { // variation of (c-b)
int m = i*999 + j*90;
std::cout << m << "\n";
}
}