I'm trying to generate all multiple cartesian products of a set S
with itself of a fixed total target string length n
, with the set containing strings of different lengths.
Eg. S = ['1', '22', '333']
with target length n=4
should output
['1111', '1122', '1221', '1333', '2211', '2222', '3331']
Also the algorithm needs to be somewhat efficient, because my final application will be of much bigger scale.
Currently my only solution is generating S^n
, cutting the results to length n
and removing duplicates, which will contain my wanted results, as well as many additional entries with the last string truncated. This algorithm doesn't scale up well, and gets unusable quickly.
I'm currently working in python, but I'm thankful for any help in pseudo code you can offer!