Introduction
Let's observe the string abc
. The substrings that can be made from this are:
a, ab, abc, b, bc, c
We now need to align them under the initial string, like this:
abc
a
b
c
ab
bc
abc
The order of the string doesn't matter, so this is also perfectly valid:
abc
a
ab
abc
b
bc
c
So, the substring is positioned under the location of the substring in the initial string. So for abcdef
and the substring cde
, it would look like this:
abcdef
cde
The Task
The task is to align all substrings with a length greater than 0, like shown above. You can assume that the string itself will only contain alphabetic characters and has at least 1 character. For the padding, you can use a space or some other non-alphabetic printable ASCII character (32 - 127
). Maybe not necessary to mention, but the string itself will only contain unique characters, so not like aba
, since the a
occurs twice.
Test cases
Input: abcde
Possible output:
a
ab
abc
abcd
abcde
b
bc
bcd
bcde
c
cd
cde
d
de
e
Input: abcdefghij
Possible output:
a
ab
abc
abcd
abcde
abcdef
abcdefg
abcdefgh
abcdefghi
abcdefghij
b
bc
bcd
bcde
bcdef
bcdefg
bcdefgh
bcdefghi
bcdefghij
c
cd
cde
cdef
cdefg
cdefgh
cdefghi
cdefghij
d
de
def
defg
defgh
defghi
defghij
e
ef
efg
efgh
efghi
efghij
f
fg
fgh
fghi
fghij
g
gh
ghi
ghij
h
hi
hij
i
ij
j
This is code-golf, so the submission with the least amount of bytes wins!