I have a string (of undertermined length) that I want to copy a lot of times replacing one character at a time from an array (of undertermined length) of characters.
So say I have this string: ‘aa’
And this array: [‘a’, ‘b’, ‘c’, ‘d’]
after some magic for-looping stuff there would be an array like: [‘aa’, ‘ab’, ‘ac’, ‘ad’, ‘ba’, ‘bb’ … ‘dc’, ‘dd’]
How would you do this? I tried something using three for loops but I just can’t seem to get it.
Edit
The dependency on the string is the following:
Say the string is: ‘ba’
then the output should be: [‘ba’, ‘bb’, ‘bc’, ‘bd’, ‘ca’ … ‘dd’]
If an order of strings in the result array doesn’t matter and all chars from the initial string are in the substitution array then:
Here’s a solution for a general case. Replacements are performed in a lexicographic order: