Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I split a string in every possible way?

Tags:

split

raku

Given the word abcd, how would I construct the following nested list?

[ (abcd) (a bcd) (ab cd) (abc d) (a b cd) (a bc d) (ab c d) (a b c d) ]

That is splitting the word in every way it can be, while keeping the letters in order.

Nemokosch on #raku-beginner pointed me to .combinations and the module snip, but I'm having trouble putting it all together.

like image 891
Jim Bollinger Avatar asked Nov 28 '25 06:11

Jim Bollinger


1 Answers

You could use match with :exhaustive:

"abcd"
andthen .match: /^ (\w+)+ $/,:ex
andthen .map: *.[0].put
like image 138
wamba Avatar answered Nov 30 '25 00:11

wamba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!