I have the following string: '12345' (the string could also be 'abcd' but I'm using numbers here for the sake of simplification).
Goal: I would like to display all the possible combinations of the characters in the string where the max length of each combination is predetermined.
For example let's take the case of a maximum length of 3 characters.
The output would display the following (it doesn't matter is which forum, it could be an array or anything else):
"1", "2", "3", "4", "5",
"11", "11", "13", "14", "15",
"21", "22", "23", "24", "25"
"31", "32", "33", "34", "35"
"41", "42", "43", "44", "45"
"51", "52", "53", "54", "55"
"111", "112", "113", "114", "115"
"121", "122", "123", "124", "125"
...
"551" "552", "553", "554", "555"
What is the right approach (pseudo code?) to achieve this task? I write in JS but the language of execution is not quite important for me.
Spent days trying to solve this without any success :-(
I managed to figure out a way to calculate the total amount of the output combinations.
- In my example case, where the string is '12345' and the max length of character-combination output is 3... the total is 155 using the following formula:
5^1 + 5^2 + 5^3 = 155
Any help towards accomplishing this task would be greatly appreciated!