Consider all the (non leading zero) positive ten-digit pandigitals arranged in descending order..
Determine the millionth number on the list.
*** Computer program/spreadsheet assisted methodologies are welcome, but extra credit will be given for an analytical solution.
There are 9! = 362880 pandigitals that begin with 9 and the same number that begin with 8, for a total of 725760.
The next group of 362880, those that begin with the digit 7, contains the sought millionth pandigital, so now we look at the second digit. There are 8! = 40320 that begin 79. The same number begin each of 78, 76, 75, 74 and 73. These six pairs of digits account for 40320 * 6 = 241920 pandigitals, in addition to the 725760 that begin with a 9 or an 8. This brings the total so far to 967680.
So now we're down into those that begin 72. There are 7! = 5040 that begin 729. Six times 5040 will fit before a total of a million is exceeded, and that's the beginnings 729, 728, 726, 725, 724, 723. The sought millionth pandigital thus begins 721....
So far, 967680 + 6*5040 = 997920 have been accounted for. There are 6! = 720 that begin 7219 and the same that begin 7218. That brings the total counted so far to 999360, and the knowledge of the beginning to 7216.
There are 5! = 120 that begin 72169. Beginnings 72169, 72168, 72165, 72164, and 72163 bring the total up to 999360 + 5 * 120 = 999960.
So the desired number starts 72160. There are 4! = 24 that begin 721609, bringing the total to 999960 + 24 = 999984, and the known digits to 721608.
There are six where the next digit is 9 and another 6 where the next digit is 5, bringing the total to 999996 and the beginning digits to 7216084.
What remains are 953, 935, 593, 539, 395 and 359. We want the fourth of these as the last three digits, so the whole is
7216084539.
Check:
>> p=perms('9876543210');
>> p=sortrows(p,'descend');
>> p(1000000,:)
ans =
'7216084539'
Since the sort was descending, leading zeros are at the end and don't interfere with the subscript.
|
Posted by Charlie
on 2023-05-29 11:34:57 |