In this puzzle, you have to place enough zeroes to make a number have a certain number of digits. For example you are expected to take the 3-digit number $123$ and are expected to make it 5 digits. So you have to place 2 zeroes in any part(except the beginning) of the number. Like,
$$12003$$ $$10023$$ $$10203$$ $$etc.$$
The thing is, the order of digit can also be changed. So these are also counted as a result. $$21003$$ $$30021$$ $$20103$$ $$etc.$$
The objective is to find the count of different positions(permutations) that this 5 digits number can have. So easy enough, This problem can be solved by the stars-and-bars method. First we find the number of permutations the 3 digit number can have. Then we use the stars and bars methods to find how many positions that the zeroes can be placed. Then multiplicate it. However there is a catch that makes this problem much harder. What if a there is a upper limit number that restricts you from using this easy method. For example if upper limit number is $28192$. The permutation $30021$ is no longer viable so must be taken off from the count. How would you solve this problem mathematically.?
Note1: First given number will not contain any zeroes.
Note2: The upper limit number will always be same digits as the target digit count.
I've written some code in python that I believe solves your problem.
The code is
I wrote it such that you can edit the digits, minnum, and maxnum variables and it will operate the same.
digitstakes in the different digits you want to find the permutations of (in this case, 1, 2, 3, 0, and 0),minnumis the minimum value the number must have to be included in the number of permutations (used to remove permutations that start with a zero), andmaxnumis the maximum value the number can have to be included in the number of permutations.The package is used to calculate permutations, and the
list_to_intfunction gets the sublists originally produced into integer format; this is then sorted and printed as the listperm. The second list,perm2, is created by iterating through each of the items in the listpermand checking if they fall within the range defined byminnumandmaxnum. Finally,perm2is sorted, printed, and the length ofperm2is calculated and printed.I compiled it in an online compiler, repl.it, and the end result given was 48. There are 48 permutations that fulfill your requirements.
Hope this helps!