h
#copy # copy input string 'A' to hold space
:
#start # start loop
s:.*:shuf -i32-126|dc -e?P:e # run shell script: shuf outputs a rnd permutation
#run shell command #of the set of numbers from 32 to replace126, patternand space'?P' within
a random printable #dc converts the 1st read decimal to an ASCII char
This works by using shuf
to output a random permutation of the input lines consisting in this case of the numbers from 32 to 126. I use dc ?
command to read only the first line, and P
to convert the read decimal to an ASCII char.
H;g
#append # append char to hold space (ex: 'A\n.'), then copy
result #result back to pattern space
s:\n::2g
#remove # remove all newlines'\n's from pattern space, but first (not needed for 1st iter)
/^(.+)\n(.*)\1/{
#if pattern is 'A\nB', with B as ' # if pattern is 'A\n.*A' (A is a substring of B), then
s::\2\1:;q
#search # search previous regex used, line above,and leave only string B'.*A',
then quit
#implicit #then quit (implicit printing before exitingexit)
}
b
#repeat # repeat loop
- input length: 1, 10 random inputs (runs), average time: < 1 s
- input length: 2, 10 random inputs (runs), average time: 90 s
- input length: 3, 10 random inputs (runs), average time: (coming soon)lots of hours!