Given a string s
, generate a set of all its unique substrings?
Example: for str = "xyx"
we would get substrs={"x", "y", "xy", "yx", "xyx"}
.
Solution:
distinct {x@raze{{{y+til x}[x] each til y}[x[0];x[1]]} each a,'reverse a:1+til count x}["xyx"]
Another way: Generate all binary combinations first (including the empty set):
bc: {$[0 >= x;:enlist(); 1 = x; :(0b; 1b); [r: bc x – 1; :((0b,’r),(1b,’r))]]}
s: {x[where each bc count x]}