32
6
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!

1Where is the empty substring? – Leaky Nun – 2016-04-27T10:23:53.597
@KennyLau Oh yes, that reminds me to edit some more info into the challenge. – Adnan – 2016-04-27T10:46:56.140
Is a trailing newline acceptable? – user81655 – 2016-04-27T11:19:47.627
@user81655 Yes, that's acceptable. – Adnan – 2016-04-27T11:20:07.063
Is an array of strings acceptable, or does it have to be newline-separated? – Zgarb – 2016-04-27T18:31:04.220
Must there also be padding after the substring ? e.g. is
ab\na\n-b\nallowed forab– Ton Hospel – 2016-04-27T18:41:05.373Does the character with ASCII code 255 count as printable ? – Ton Hospel – 2016-04-27T18:44:18.317
@Zgarb An array of strings is also acceptable. – Adnan – 2016-04-27T21:27:23.693
@TonHospel No, padding after the substring is not necessary. Also, with printable ASCII, I meant ASCII characters in the range
32 - 127. I'll edit that into the challenge. – Adnan – 2016-04-27T21:28:32.887Would a set of strings be OK for the output? – xnor – 2016-04-27T22:55:12.203
@xnor You mean like
["ab", " b", "a"]? That's fine. They have to be padded with spaces at the left though. – Adnan – 2016-04-27T23:00:09.883@Adnan I meant like
{"ab", " b", "a"}in Python, wheresetis a built-in data type that is unordered and enforces uniqueness. – xnor – 2016-04-27T23:01:30.750@xnor Oh, that is fine. The uniqueness also doesn't matter because the input string itself will always contain unique characters (e.g. not
aba). – Adnan – 2016-04-27T23:02:28.427Is it okay if the lines are padded on both sides instead of just the left? – Cyoce – 2016-07-14T01:15:20.067
@Cyoce As long as the same letters are in the same row. – Adnan – 2016-07-14T01:25:07.370