# Challenge

Given a string, make it into a triangle as shown below:

### Input

Hello, world!


### Output

H
He
Hel
Hell
Hello
Hello,
Hello,
Hello, w
Hello, wo
Hello, wor
Hello, worl
Hello, world
Hello, world!


The first line contains the first character of the string. The following lines contain one more character on each line, until the full length of the original string is reached.

If you receive a one character string, just output it.

You will never receive an empty string.

## Rules

• Standard loopholes apply, as usual
• This is , shortest solution wins.
• Have we really not had this challenge before?
– xnor
Jul 8 '17 at 1:55
• @xnor Not from my searching Jul 8 '17 at 1:56
• Second half of this Jul 8 '17 at 2:01
• @WheatWizard Oooops Jul 8 '17 at 2:02
• Trailing newline OK? (Is there a default?)
– xnor
Jul 8 '17 at 2:05

# Jelly, 3 bytes

;\Y


Try it online!

• and of course Dennis crushes the competition within 3 minutes. GG Jul 8 '17 at 1:55
• @Mendeleev By the way, even APL gets three bytes, ↑,\ Jul 8 '17 at 5:04

# brainfuck, 23 bytes

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


Try it online!

# Python, 33 bytes

f=lambda s:s and f(s[:-1])+s+'\n'


Try it online!

# J, 2 bytes

[\


Tailor made for J. This is just a scan \ using the identity function [.

Try it online! -- Note the extra space in the output on line 1 is just a quirk of TIO in this case. It does not appear when run in jconsole.

• Better formatting: tio.run/##y/r/P03B1kohOuZ/… [\ would count as a tacit verb here. Jul 8 '17 at 5:12
• Thanks @Dennis. What did you mean by "count it as a tacit verb"? Is 2 bytes not a fair count according to community rules here? I'm still fairly new to this.... Jul 8 '17 at 5:40
• Yes, 2 bytes is fine. We allow anonymous functions, and that's just what [\ is. Jul 8 '17 at 6:09

# Haskell, 28 bytes

g[]=[]
g a=(g.init)a++'\n':a


Try it online!

Pretty straight forward. The base case is the empty string and each other case is a recursive call to init to the string with a newline and the input added to the end.

Here are my three attempts at a non-recursive solution all of which are exactly the same length.

g a=concat['\n':take x a|(x,_)<-zip[1..]a]
g a=concat['\n':take(fst x)a|x<-zip[1..]a]
g a=concat['\n':take x a|x<-[1..length a]]


And here's one that I found that is shorter than all of them

g a=do(x,_)<-zip[1..]a;'\n':take x a


I also came up with this very strange solution I quite like (its longer than the others though):

g a=zip[1..](a>>[a])>>=('\n':).uncurry take


Try it online!

òÄ$xh  Try it online! # Python 2, 49 bytes lambda s:'\n'.join(s[:i]for i in range(len(s)+1))  Try it online! Meanwhile, I'm like, how is this is impossible right now in my language?! # Python 2, 34 bytes s='' for c in input():s+=c;print s  Try it online! # C (gcc), 57 bytes i;f(char*s){for(i=0;i<strlen(s);puts(""))write(1,s,++i);}  Try it online! # Ruby, 31 + 1 = 32 bytes Uses -n flag. a=''$_.each_char{|i|puts a<<i}


Try it online!

• Why use a newline instead of a semicolon? Newlines are bytes too... Jul 8 '17 at 2:17
• Newlines are more readable. Jul 8 '17 at 2:17

# Ruby, 35 bytes

->s{a='';s.each_char{|c|puts a<<c}}

• Full program seems to be shorter. Jul 8 '17 at 2:16
• @Phoenix I noticed. Jul 8 '17 at 2:16