87
12
Hold up..... this isn't trolling.
Background
These days on YouTube, comment sections are littered with such patterns:
S
St
Str
Stri
Strin
String
Strin
Stri
Str
St
S
where String
is a mere placeholder and refers to any combination of characters. These patterns are usually accompanied by a It took me a lot of time to make this, pls like
or something, and often the OP succeeds in amassing a number of likes.
The Task
Although you've got a great talent of accumulating upvotes on PPCG with your charming golfing skills, you're definitely not the top choice for making witty remarks or referencing memes in YouTube comment sections. Thus, your constructive comments made with deliberate thought amass a few to no 'likes' on YouTube. You want this to change. So, you resort to making the abovementioned clichéd patterns to achieve your ultimate ambition, but without wasting any time trying to manually write them.
Simply put, your task is to take a string, say s
, and output 2*s.length - 1
substrings of s
, delimited by a newline, so as to comply with the following pattern:
(for s
= "Hello")
H
He
Hel
Hell
Hello
Hell
Hel
He
H
Input
A single string s
. Input defaults of the community apply.
You can assume that the input string will only contain printable ASCII characters.
Output
Several lines separated by a newline, constituting an appropriate pattern as explained above. Output defaults of the community apply. Leading and trailing blank (containing no characters or characters that cannot be seen, like a space) lines in the output are permitted.
Test Case
A multi-word test case:
Input => "Oh yeah yeah"
Output =>
O
Oh
Oh
Oh y
Oh ye
Oh yea
Oh yeah
Oh yeah
Oh yeah y
Oh yeah ye
Oh yeah yea
Oh yeah yeah
Oh yeah yea
Oh yeah ye
Oh yeah y
Oh yeah
Oh yeah
Oh yea
Oh ye
Oh y
Oh
Oh
O
Note that there are apparent distortions in the above test case's output's shape (for instance, line two and line three of the output appear the same). Those are because we can't see the trailing whitespaces. Your program need NOT to try to fix these distortions.
Winning Criterion
This is code-golf, so the shortest code in bytes in each language wins!
20I am planning to make some more YouTube comments related challenges in the future; hence the
YouTube Comments #1
in the title. – Arjun – 2019-02-27T10:31:57.5531Is returning a array of lines allowed? – my pronoun is monicareinstate – 2019-02-27T11:00:23.830
@someone Yes, it is allowed, in accordance with standard I/O defaults – Arjun – 2019-02-27T11:09:57.880
2Can we take input as an array of characters and return an array of arrays of characters? – Shaggy – 2019-02-27T11:43:46.453
3Closely related – Giuseppe – 2019-02-27T15:49:16.650
3Can the input be
""
? What about a single character like"H"
? If so, what should be the output for both of those cases? – AdmBorkBork – 2019-02-27T20:41:18.1501@AdmBorkBork No, the input cannot be
""
. As for"H"
, the desired output isH
only. I am sincerely sorry for such a late reply. – Arjun – 2019-02-28T14:21:24.927@Shaggy If the community rules allow it, then sure. – Arjun – 2019-02-28T14:25:25.557
Are leading and trailing blank lines permitted? (i.e. output is
2*s.length + 1
lines, but the first and last lines are empty) – Chronocidal – 2019-02-28T16:44:38.997Can we assume the input only contains chars in the ASCII 32--127 range? In particular, can we assume it doesn't contain char(0)? – Luis Mendo – 2019-03-01T10:27:50.713
@Chronocidal Yes, leading and trailing blank lines are permitted. – Arjun – 2019-03-04T03:46:08.600
@LuisMendo Yes, you can assume that the input will only contain printable ASCII characters. I'll edit accordingly. – Arjun – 2019-03-04T03:47:38.000