I'm trying to write a method that would take 'abcd' as an input, and return:
["a b c d", "a b cd", "a bc d", "a bcd", "ab c d", "ab cd", "abc d", "abcd"]
so, all possible ways of splitting a string into n substrings that when you concatenage s1 + s2 + s3 + ... you get back the original string.
I have solved it like this, but I feel like there should be a faster and more straightforward way to do it.
def sequence(n) [true, false].repeated_permutation(n).to_a end def breakdown4(string) guide = sequence(string.length-1) arr =  guide.each do |i| s = string.dup counter = 0 i.each do |j| if j s.insert(counter+1, " ") p counter counter += 2 else counter += 1 end end arr.push(s) end arr end