If I have a string such as ‘abcde’ and I want to get a 2d array of all combinations of 1 or 2 letters.
[ ['a', 'b', 'c', 'd', 'e'], ['ab', 'c', 'de'], ['a', 'bc', 'd', 'e'] ...
How would I go abouts doing so?
I want to do this in ruby, and think I should be using a regex. I’ve tried using
strn = 'abcde'
strn.scan(/[a-z][a-z]/)
but this is only going to give me the distinct sets of 2 characters
['ab', 'cd']
I think this should do it (haven’t tested yet):