If all the 40320 (base 10) permutations of 12345678 in the hexadadecimal (base 16) representation are put in numerical order, what is the 20230th (base ten) pemutation?
There are 5040 permutations that begin with 1, and the same number that begin with each of 2, 3 and 4. that's 20,160 that begin with these, ending with 48765321. The 20,161st is then 51234678, but we need the 70th in the sequence starting at 51234678.
24 of those begin 5123; another 24 begin 5124 and another 24 with 5126. That takes us up to the 20232nd permutation, two beyond our goal. That 20232nd permutation is 51268743; the one before that was 51268734; before that, 51268473, which is then our answer.
Check:
>> a=perms(1:8);
>> a=sortrows(a);
>> a(20230,:)
ans =
5 1 2 6 8 4 7 3
|
Posted by Charlie
on 2023-07-25 09:38:49 |