# It took me a lot of time to make this, pls like. (YouTube Comments #1)

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.

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 , so the shortest code in bytes in each language wins!

• I am planning to make some more YouTube comments related challenges in the future; hence the YouTube Comments #1 in the title. – Arjun Feb 27 '19 at 10:31
• Is returning a array of lines allowed? – the default. Feb 27 '19 at 11:00
• Can we take input as an array of characters and return an array of arrays of characters? – Shaggy Feb 27 '19 at 11:43
• Closely related – Giuseppe Feb 27 '19 at 15:49
• Can the input be ""? What about a single character like "H"? If so, what should be the output for both of those cases? – AdmBorkBork Feb 27 '19 at 20:41

# brainfuck, 32 bytes

,[[<]>[.>]++++++++++.,[>>]<[-]<]

Try it online!

The same loop is used for both halves of the pattern.

### Explanation:

,             Take first input character as initial line
[             Until line to output is empty:
[<]>        Move to beginning of line
[.>]        Output all characters in line
++++++++++. Output newline
,           Input next character
[>>]        Move two cells right if input character nonzero
<[-]        Otherwise remove last character in line
<           Move to new last character in line
]
• That's just plain awesome. I was trying to do something in brainfuck but it came out about 10 times this long and still didn't work properly. – ElPedro Feb 27 '19 at 22:09
• Never thought I'd see a challenge where the brainfuck answer was actually scoring competitively, awesome work! – Question Marks Feb 28 '19 at 18:01

# JavaScript (ES6), 36 bytes

f=([c,...r],s=
)=>c?s+f(r,s+c)+s:s

Try it online!

### Commented

f = (             // f is a recursive function taking:
//   the input string split into:
[c,             //     c   = next character (may be undefined if we've reached the end)
...r],      //     r[] = array of remaining characters
s = \n        //   the output string s, initialized to a linefeed
) =>              //
c ?             // if c is defined:
s +           //   append s (top of the ASCII art)
f(r, s + c) + //   append the result of a recursive call to f, using r[] and s + c
s             //   append s again (bottom of the ASCII art)
:               // else:
s             //   append s just once (this is the final middle row) and stop recursion
• very nice answer :D – lois6b Feb 27 '19 at 15:38
• different OSes different sizes got to hate line endings so windows reports as 37 bytes because of \r\n over Unix \n :D – Martin Barker Feb 27 '19 at 16:57
• @MartinBarker On Windows, I'm using Notepad++ with the default Line Ending turned to Unix (LF). Problem solved once and for all. :) – Arnauld Feb 27 '19 at 17:00
• Longer than the BF solution...that's a first – Redwolf Programs Oct 31 '19 at 3:02

# 05AB1E (legacy),  4  3 bytes

Crossed out &nbsp;4&nbsp; is no longer 4 :)

η.∊

Explanation:

η     # Get the prefixes of the (implicit) input-string
.∊   # Vertically mirror everything with the last line overlapping
# (which implicitly joins by newlines in the legacy version of 05AB1E)
# (and output the result implicitly)

In the new version of 05AB1E, and explicit » is required after the η, which is why I use the legacy version of 05AB1E here to save a byte.

3 bytes alternative provided by @Grimy:

ηû»

This version works in both the legacy and new version of 05AB1E.

Explanation:

η     # Get all prefixed of the (implicit) input-string
û    # Palindromize each string in this list
»   # And then join the list of strings by newlines
# (after which the result is output implicitly)
• Hmm, this seems to 6 bytes in UTF8: \xce\xb7\x2e\xe2\x88\x8a – rubenvb Feb 28 '19 at 17:22
• @rubenvb In UTF-8 it's indeed more. 05AB1E uses, just like some some of the programming languages used in other answers (i.e. Jelly; Japt; Charcoal) it's own source code (which is CP-1252 in the case of 05AB1E), where each of the 256 characters it knows is a single byte. – Kevin Cruijssen Feb 28 '19 at 17:30
• All right, fair enough :). – rubenvb Feb 28 '19 at 17:31
• @hanshenrik Good question. It is indeed not CP-1252, but in fact the 05AB1E encoding, which is the custom encoding it uses. The bytes of this code in hex are 08 2e 17, which you can run and verify with the --osabie flag: tio.run/… – Adnan Mar 2 '19 at 12:20
• ηû» for modern 05AB1E. – Grimmy Oct 31 '19 at 16:54

# x86-16 machine code, IBM PC DOS,  44 43 39 bytes

00000000: d1ee ad8b d648 93b7 248a cbd0 e13a d975  .....H..$....:.| 00000010: 01fd ac86 3cb4 09cd 2186 3cb8 0d0e cd10 ....<...!.<..... 00000020: b00a cd10 e2e7 c3 ....... Build and test YT.COM using xxd -r from above. Unassembled: D1 EE SHR SI, 1 ; point SI to DOS PSP at 80H (SI intialized at 100H) AD LODSW ; load input length into AL, SI = 82H 8B D6 MOV DX, SI ; save start of string pointer 48 DEC AX ; remove leading space from string length 93 XCHG AX, BX ; save string length in BL B7 24 MOV BH, '$'            ; put end-of-string marker in BH
8A CB       MOV  CL, BL             ; set up loop counter in CL
D0 E1       SHL  CL, 1              ; number of lines = 2 * string length - 1
LINE_LOOP:
3A D9       CMP  BL, CL             ; does CL = string length?
75 01       JNZ  LINE_OUT           ; if not, go to output line
FD          STD                     ; otherwise flip DF to descend
LINE_OUT:
AC          LODSB                   ; increment or decrement SI
86 3C       XCHG BH, [SI]           ; swap current string byte with end of string delimiter
B4 09       MOV  AH, 9              ; DOS API display string function
CD 21       INT  21H                ; write substring to console
86 3C       XCHG BH, [SI]           ; restore string byte
B8 0E0D     MOV  AX, 0E0DH          ; AH = 0EH (BIOS tty function), AL = CR char
CD 10       INT  10H                ; write CR to console
B0 0A       MOV  AL, 0AH            ; AL = LF char
CD 10       INT  10H                ; write LF to console
E2 E6       LOOP LINE_LOOP          ; move to next line

Explanation

Try it online!

# PowerShell, 42 bytes (YouTube special, dirty)

It is known that the maximum length of a comment on youtube is 10,000 characters. Ok, use this as the upper limit.

($l=$args|% t*y|%{($s+=$_)})+$l[1e4..0]|gu Try it online! # Ruby, 5142 40 bytes f=->s,i=1{s[i]?[t=s[0,i],*f[s,i+1],t]:s} Try it online! Thanks to Doorknob for -2 bytes. • You can save 2 bytes by replacing ... with , – Doorknob Feb 27 '19 at 13:17 # JavaScript (Node.js), 90 bytes This can probably be golfed alot more, Arnauld already has a way shorter one but I had fun atleast! s=>{a=[];for(c=s.length-1;c--;)a[c]=s.slice(0,c+1);return[...a,s,...a.reverse()].join\n} Try it online! # SNOBOL4 (CSNOBOL4), 118 bytes N =INPUT L =1 1 X =LT(X,SIZE(N)) X + 1 :F(D) O N ARB . OUTPUT POS(X) :($L)
D	X =GT(X) X - 1	:F(END)
L ='D'	:(O)
END

Try it online!

There appears to be a bug in this implementation of SNOBOL; attempting to replace the label D with the label 2 causes an error, although the manual for Vanilla SNOBOL indicates that (emphasis added)

If a label is present, it must begin with the first character of the line. Labels provide a name for the statement, and serve as the target for transfer of control from the GOTO field of any statement. Labels must begin with a letter or digit, optionally followed by an arbitrary string of characters. The label field is terminated by the character blank, tab, or semicolon. If the first character of a line is blank or tab, the label field is absent.

My supposition is that the CSNOBOL interpreter only supports a single label that begins with an integer.

# APL+WIN, 31 bytes

Prompts for input of string:

⊃((⍳n),1↓⌽⍳n)↑¨(¯1+2×n←⍴s)⍴⊂s←⎕

Explanation:

(¯1+2×n←⍴s)⍴⊂s create a nested vector of the string of length =1+2x length of string

((⍳n),1↓⌽⍳n)↑¨ progressively select elements from each element of the nested vector
following the pattern 1  2 ...to n to n-1 ... 1

⊃ convert nested vector into a 2d array.

# F# (.NET Core), 67 61 bytes

let l=s.Length
[1..l*2-1]|>Seq.map(fun i->s.[..l-abs(i-l)-1])

Try it online!

Input is a string and output is a seq<string>

Another solution could be let f(s:string)=for i=1 to s.Length*2-1 do printfn"%s"s.[..s.Length-abs(i-s.Length)-1] for 80ish bytes... I am not sure that it is worth looking into.

# sed, 31 35 bytes

:x
h
s/.\n.*\|.$// /^$/{x;q}
H
G
bx

Try it online!

# Explanation

At the beginning of each iteration of the loop, pattern space is some "central chunk" of the desired output, and each loop adds a shortened copy to the top and bottom.

:x
h                  Copy the current chunk to hold space
s/.\n.*\|.$// Remove the last letter of the first line, and all other lines (if there are any) /^$/{x;q}          If pattern space is empty we're done; output hold space
H                  Add the shortened line to the end of hold space
G                  and add the new hold space to pattern space.
bx
• Nice one, but the the middle line (the full original input) seems to be output 3 times. At least with GNU sed. Same on TIO. Which sed implementation you use and how you pass it the input? (BTW, changing the substitution to s/.\n.*\|.\$// fixes it.) – manatwork Feb 28 '19 at 13:12
• Ah, you're right. It's not a problem with my sed implementation (using GNU version 4.2.1) , I just didn't notice the bug. I've played around with some other fixes and can't find anything that adds fewer than four bytes so I'm adopting your fix, thank you. – Sophia Lechner Feb 28 '19 at 18:22

# J, 12 bytes

]\,[:}.@|.]\

Try it online!

Still 1 byte longer than Adám's

# K (oK), 12 11 bytes

-1 byte thanks to ngn

{x,1_|x}@,\

Try it online!

• Did I outgolf the master‽ – Adám Feb 27 '19 at 11:56
• @Adám I'm far from being a J master :) There are many J coders here better than I am. – Galen Ivanov Feb 27 '19 at 12:00
• -1 byte for oK: {x,1_|x}@,\ – ngn Feb 28 '19 at 22:31
• @ngn Thank you! – Galen Ivanov Mar 1 '19 at 4:51

# C (gcc), 686764 59 bytes

thanks @ceilingcat for -6 thanks @gastropner for -5

i,j;f(char*s){for(j=1;i+=j;puts(""))j-=2*!s[write(1,s,i)];}

Try it online!

• Does not appear to be reusable. – gastropner Feb 28 '19 at 12:50
• @gastropner what do you mean, not reusable? – Baldrickk Feb 28 '19 at 17:12
• @Baldrickk If you call the function again with a new string, it doesn't work. – gastropner Feb 28 '19 at 17:13
• – gastropner Feb 28 '19 at 18:32
• 59 bytes – gastropner Mar 8 '19 at 14:05

# Octave, 58 bytes

for k=1:(n=nnz(s=input(''))*2)-1
disp(s(1:min(k,n-k)))
end

Try it online!

• I came up with essentially the same answer in MATLAB before I saw yours, but you get to take shortcuts in Octave with those compound assignments saving several bytes... I did briefly consider if any char maps to zero, such that nnz would miss it? – Wolfie Mar 1 '19 at 8:58
• @Wolfie Somehow I assumed the input would not contain char(0), but you are right, it might be the case. I've asked for the OP if we can assume the standard ASCII range 32--127 – Luis Mendo Mar 1 '19 at 10:28
• @Wolfie Confirmed: only printable ASCII – Luis Mendo Mar 4 '19 at 9:48