Let us consider all possible positive whole numbers (not containing any leading zeroes) with the proviso that in each of the numbers, none of its digits can be repeated.
Note: any given number may or may not contain all the digits from 0 to 9 (Examples: 7; 20; 1056; 3067941825 etc.)
These numbers are now arranged in descending order of magnitude.
What would be the 200,136th number?
(In reply to
solution by Charlie)
By taking the permutations of all ten digits in ascending order of value, and counting down from 10! = 3628800, when we get to a count of 200136, that will be the 200,136th in descending order.
DECLARE SUB permute (a$)
DEFLNG AZ
CLS
a$ = "0123456789": h$ = a$
ct = 3628800
DO
permute a$
ct = ct  1
LOOP UNTIL a$ = h$ OR ct = 200136
PRINT a$
The permute subroutine is shown elsewhere on this site.
The answer agrees, as 9403152678.

Posted by Charlie
on 20060202 12:45:28 