I had a combinatorics assignment that involved getting every word with length less than or equal to 6 from a specific combination of strings.
In this case, it was S = { ‘a’, ‘ab’, ‘ba’ }. The professor just started listing them off, but I thought it would be easier solved with a program. The only problem is that I can’t get a good algorithm that would actually compute every possible option.
If anyone could help, I’d appreciate it. I usually program in Python but really I just need help with the algorithm.
You can iteratively generate all the strings made from one part, two parts, three parts and so on, until all the strings generated in a step are longer than six characters. Further steps would only generate even longer strings, so all possible short strings have already been generated. If you collect these short strings in each step you end up with a set of all possible generated short strings.
In Python: