I have 100,000 strings of length 10, which needs to be split in 9 ways as shown below
10 # the whole string
5 x 5 # 2 strings of length 5 each
4 x 6 # and so on...
6 x 4
3 x 3 x 4
3 x 4 x 3
4 x 3 x 3
3 x 7
7 x 3
So for example the string WGWJAWMPPJ would turn into
WGWJAWMPPJ
WGWJA WMPPJ
WGWJ AWMPPJ
WGWJAW MPPJ
WGW JAW MPPJ
WGW JAWM PPJ
WGWJ AWM PPJ
WGW JAWMPPJ
WGWJAWM PPJ
The code I wrote is below
def breakdown(str)
[
[str],
[str[0..4], str[5..9]],
[str[0..3], str[4..9]],
[str[0..5], str[6..9]],
[str[0..2], str[3..5], str[6..9]],
[str[0..2], str[3..6], str[7..9]],
[str[0..3], str[4..6], str[7..9]],
[str[0..2], str[3..9]],
[str[0..6], str[7..9]]
]
end
Is there any way to improve the performance of the above method?
Stringclass. The operations you are performing, are what ropes are very good at.