Project Euler 885 - Sorted Digits
Project Euler 885 - Sorted Digits
Official link: https://projecteuler.net/problem=885
Thought Process
Thought Process
There are (n + 9)C9 strings sorted in ascending order. Think of stars and bars where the bars indicate how many number have a certain value, (method is shown here).Â
For our case n = 18, hence we only have 27C9 = 4,686,825 possibilities hence we can brute force.
To generate them all I used itertools.combinations_with_replacement, then for each increasing number, call it y, we need to count how many permutations, x, of the digits of y there are such that f(x) = y.
The number of permutations is n!/(d0!d1!d2!d3!d4!d5!d6!d7!d8!d9!), where di = number of times digit i appears in y.
Interactive Code
Interactive Code
Input an integer (yourinput)
Code will output S(yourinput)