42
\$\begingroup\$

The Challenge

Your task is to create a program or function that outputs the following with no input:

a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh iiiiiiiii jjjjjjjjjj kkkkkkkkkkk llllllllllll mmmmmmmmmmmmm nnnnnnnnnnnnnn ooooooooooooooo pppppppppppppppp qqqqqqqqqqqqqqqqq rrrrrrrrrrrrrrrrrr sssssssssssssssssss tttttttttttttttttttt uuuuuuuuuuuuuuuuuuuuu vvvvvvvvvvvvvvvvvvvvvv wwwwwwwwwwwwwwwwwwwwwww xxxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyyyyyyyy zzzzzzzzzzzzzzzzzzzzzzzzzz 

You may use the uppercase alphabet instead of lowercase if you prefer. Trailing/leading newlines or spaces are allowed.

Scoring

This is , so the shortest answer in each language wins.

\$\endgroup\$
14
  • 4
    \$\begingroup\$ Output as list of lines? \$\endgroup\$ Commented Nov 8, 2017 at 22:19
  • 5
    \$\begingroup\$ Can we use the uppercase alphabet instead? \$\endgroup\$ Commented Nov 8, 2017 at 22:20
  • 9
    \$\begingroup\$ I was missing alphabet challenges! (but don't let Leaky Nun know) \$\endgroup\$ Commented Nov 8, 2017 at 22:32
  • 11
    \$\begingroup\$ I worked very hard checking if it was a dupe and apparently it isn't \$\endgroup\$ Commented Nov 8, 2017 at 22:35
  • 5
    \$\begingroup\$ @totallyhuman that's up to you. \$\endgroup\$ Commented Nov 8, 2017 at 23:31

123 Answers 123

1
2 3 4 5
23
\$\begingroup\$

Python 2, 36 bytes

i=1 exec'print chr(i+96)*i;i+=1;'*26 

Try it online!

\$\endgroup\$
15
\$\begingroup\$

05AB1E, 2 bytes

Try it online!

Note that this outputs as a list of lines, as the OP explicitly allowed. The link uses a version with pretty-print (joined by newlines).

How it works

  • A yields the lowercase alphabet.
  • ƶ lifts the alphabet (multiplies each element by its index).
  • » joins by newlines.
\$\endgroup\$
0
12
\$\begingroup\$

APL (Dyalog), 12 8 5 bytes SBCS

3 bytes saved thanks to @ngn

4 bytes saved thanks to @Adám

⍴⍨⌸⎕A 

OP clarified uppercase letters are valid, as well as output as an array of strings.

Try it online!

How?

gives us every letter in the ⎕A lphabet with its indexes in it, handed into the function ⍴⍨ with the letter as left argument and the indexes as right argument.

⍴⍨ resha es its right argument to the length supplied by its left one. switches the left and right (therefore the symbol of it, looking like the face of someone reading this explanation).

\$\endgroup\$
14
  • \$\begingroup\$ 819⌶↑⎕A⍴¨⍨⍳26 \$\endgroup\$ Commented Nov 8, 2017 at 23:06
  • \$\begingroup\$ @Adám thanks! I tried all variations of / and \, completely ignored shape ⍨ \$\endgroup\$ Commented Nov 8, 2017 at 23:12
  • \$\begingroup\$ You can remove the too. \$\endgroup\$ Commented Nov 8, 2017 at 23:40
  • \$\begingroup\$ @Adám but it would look uglier ⍨ \$\endgroup\$ Commented Nov 8, 2017 at 23:42
  • \$\begingroup\$ Turn boxing on! \$\endgroup\$ Commented Nov 8, 2017 at 23:42
9
\$\begingroup\$

Haskell, 27 bytes

[c<$['a'..c]|c<-['a'..'z']] 

Try it online! Returns a list of lines. (Thanks to @totallyhuman for pointing out that this is now allowed)

Explanation:

 c<-['a'..'z'] -- for each character c from 'a' to 'z' [ |c<-['a'..'z']] -- build the list of [ ['a'..c]|c<-['a'..'z']] -- the lists from 'a' to c, e.g. "abcd" for c='d' [c<$['a'..c]|c<-['a'..'z']] -- with each element replaced by c itself, e.g. "dddd" 
\$\endgroup\$
3
  • \$\begingroup\$ *bows* Explanation for a noob? Does <$ repeat its first argument n times, where n is the length of its second argument? \$\endgroup\$ Commented Nov 8, 2017 at 22:43
  • \$\begingroup\$ @totallyhuman There you go. Feel free to ask in Of Monads and Men if you have further questions. \$\endgroup\$ Commented Nov 8, 2017 at 22:52
  • \$\begingroup\$ There are some very interesting operators in Prelude... Thanks for the explanation! \$\endgroup\$ Commented Nov 8, 2017 at 22:54
9
\$\begingroup\$

Ruby, 32 30 bytes

-2 bytes thanks to @EricDuminil.

27.times{|n|puts (n+96).chr*n} 

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Excellent. According to a comment by OP, trailing/leading newlines are allowed. In that case 27.times{|n|puts (n+96).chr*n} would be correct with 30 bytes \$\endgroup\$ Commented Nov 9, 2017 at 9:59
8
\$\begingroup\$

brainfuck, 74 bytes

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

Try it online!

Explanation

++++++++[>+>+++>++++++++++++<<<-]>++>++>+>+ TAPE: 000 010 C_NEWLINE 026 V_ITERCOUNT 097 V_ALPHA >001< V_PRINTCOUNT 000 T_PRINTCOUNT V_ITERCOUNT TIMES: <<[- V_PRINTCOUNT TIMES: >>[- INC T_PRINTCOUNT >+ OUTPUT V_ALPHA <<. >] RESTORE V_PRINTCOUNT >[-<+>] INC V_PRINTCOUNT <+ INC V_ALPHA <+ OUTPUT C_NEWLINE <<. >] 

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ 70 bytes (Would be even lower if uppercase letters were used instead) \$\endgroup\$ Commented Mar 2 at 14:37
8
\$\begingroup\$

JavaScript (ES6), 54 bytes

f=(n=9)=>++n<36?n.toString(36).repeat(n-9)+` `+f(n):'' O.innerText = f()
<pre id=O></pre>

\$\endgroup\$
8
\$\begingroup\$

Befunge-98 (FBBI), 27 bytes

1+:0\::'`j'@+\k:$$>:#,_$a, 

where  is a substitution character (ASCII 26)

Try it online!

Uses uppercase letters, and has a trailing newline.

Explanation

The code works by storing a counter (0 initially), and on every loop:

  • 1+ - Increments it by 1
  • :0\:: - Pushes things so that the stack looks like this: bottom [N, 0, N, N, N] top
  • '`j'@ - Checks if the counter is greater than 26
    • j'@ - If it is, we jump over the ' and exit using @
    • j'@ - If it isn't, we execute the ', which pushes the ASCII value of @ to the stack

Now the stack looks like this: bottom [N, 0, N, N, 64] top

  • +\ - Adds, then switches the top 2: bottom [N, 0, (N+64), N] top The first time through, this is ASCII 65, or A
  • k: - Duplicates the second from the top (N+1) times - now there are (N+2) values of (N+64) on the stack (plus the N and 0 from earlier)
  • $$ - Throw away the top 2 values - now there are only N values of (N+64)
  • >:#,_ - Prints each top value until it gets to a 0 - this means N copies of (N+64) get printed
  • $ - Throws away the 0 - Now the stack is just N
  • a, - Prints an enter

And it repeats


I like how I used the @ both for ending the program and for adding to the counter.

\$\endgroup\$
0
7
\$\begingroup\$

Excel VBA, 38 bytes

Using Immediate Window. :)

[A1:A26]="=REPT(CHAR(96+ROW()),ROW())" 
\$\endgroup\$
2
  • \$\begingroup\$ Ah. My bad. I thought it's Excel because I used Excel Functions using Immediate Window. \$\endgroup\$ Commented Dec 19, 2017 at 2:58
  • \$\begingroup\$ You can drop a byte by removing the terminal " \$\endgroup\$ Commented Jan 30, 2018 at 17:48
6
\$\begingroup\$

V, 9 bytes

¬az\ÓÎÛäl 

Try it online!

Hexdump:

00000000: ac61 7a5c d3ce dbe4 6c .az\....l 
\$\endgroup\$
6
\$\begingroup\$

BASH, 59 54 40 bytes

for l in {a..z};{ a+=a echo ${a//a/$l} } 

Try it online!

thx. 5 bytes to @Justin Mariner

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The for loop can be golfed down using this tip for 54 bytes: Try it online! \$\endgroup\$ Commented Nov 9, 2017 at 0:24
6
\$\begingroup\$

Ruby, 38 bytes

Returns an Array of strings

->{(a=*?a..?z).map{|x|x*-~a.index(x)}} 

-5 bytes thanks to totallyhuman

*-11 bytes thanks to some excellent golfing by Jordan.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ You don’t need "\n" at all; puts does that for you (though for future reference $/ is 2 bytes shorter)—but you can get rid of puts entirely if you make this a lambda that just returns an array of lines. You can also change a=[*?a..?z];puts a.map to puts (a=*?a..?z).map and x*(a.index(x)+1) to x*-~a.index(x). All together that’s 38 bytes. \$\endgroup\$ Commented Nov 9, 2017 at 1:28
  • \$\begingroup\$ The 38-byte version works fine on TiO (see link in previous comment). Note that the (a=*?a..?z) is inside the block, not the arguments part of the lambda. \$\endgroup\$ Commented Nov 16, 2017 at 6:48
6
\$\begingroup\$

Acc!!, 66 64 bytes

Count i while 27-i { Count j while i-j { Write 96+i } Write 10 } 

Outputs with a leading and trailing newline. Try it online!

With comments

# Loop i from 0 to 26 Count i while 27-i { # Loop j from 0 to i (exclusive) Count j while i-j { # Print the i'th letter (1-indexed) Write 96+i } # Print a newline Write 10 } 
\$\endgroup\$
0
5
\$\begingroup\$

Pip, 9 bytes

FczPcX++i 

Try it online!

In pseudocode, this is

For-each c in z Print (c string-multiply ++i) 

where z is preset to the lowercase alphabet and i is preset to 0.


Map-based solutions take one extra byte because they need the -n flag to display on multiple lines:

{aX++i}Mz B X_+1MEz 
\$\endgroup\$
5
\$\begingroup\$

Haskell, 31 bytes

-12 bytes thanks to nimi.

zipWith replicate[1..26]['a'..] 

Try it online!

This is not a snippet, it is a nullary function (one that takes no arguments) that outputs a list of lines which is allowed because of this meta consensus.

\$\endgroup\$
0
5
\$\begingroup\$

Python 3, 37 bytes

for k in range(27):print(chr(k+96)*k) 

Prints a leading newline (which is allowed).

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Jelly,  5  4 bytes

sneaky Python implementation abuse

-1 byte thanks to Adám (outputting a list of lines has been allowed; as, now, has writing a function rather than a program)

Øa×J 

A niladic link that returns a list of strings, the lines
(to print it with the newlines as a full program just add Y back in).

Try it online! (the footer calls the link as a nilad (¢) and gets the Python representation of the result (ŒṘ) for clarity as the default full-program behaviour would smash the result together like abbccc...)

How?

Øa×J - main link: no arguments Øa - yield the alphabet = ['a','b','c',...,'z'] J - range of length = [1,2,3,...,26] × - multiplication = ["a","bb","ccc",...,"zzzzzzzzzzzzzzzzzzzzzzzzzz"] - (Python multiplication lengthens chars to strings - not usually a Jelly thing) 
\$\endgroup\$
3
  • 1
    \$\begingroup\$ Øa×J should be enough. \$\endgroup\$ Commented Nov 8, 2017 at 23:40
  • \$\begingroup\$ hmm, maybe - we may "output" a list of lines, but we must "create a program" - when running as a program the output of the four byter is smashed to have no indication of it's list nature. \$\endgroup\$ Commented Nov 9, 2017 at 0:02
  • \$\begingroup\$ program or function \$\endgroup\$ Commented Nov 9, 2017 at 0:53
5
\$\begingroup\$

MATL, 11 bytes

2Y2t!g*!YRc 

Try it online!

Uses broadcast multiplication with ones to get a big square 26x26 matrix of the desired letters. Next, the lower triangular part is taken, and implicitly printed.

Also 11 bytes:

2Y2!t~!+YRc % Using broadcast addition with zeroes 2Y2!l26X"YR % Using 'repmat' 
\$\endgroup\$
1
  • \$\begingroup\$ @StewieGriffin I was actually halfway commenting on your Octave answer on the coincidence of coming up with the same solution. \$\endgroup\$ Commented Nov 9, 2017 at 14:28
5
\$\begingroup\$

Javascript, 87 bytes, 72 bytes (A lot of thank to @steenbergh)

My first answer too:

for(i=1,j=97;j<123;){console.log(String.fromCharCode(j++).repeat(i++))}; 
\$\endgroup\$
3
  • \$\begingroup\$ Welcome! Looks like you can shorten it a bit by removing the spaces around ind=1at the start, the semicolon after i<123 and the final semicolon. also, please make your header slightly more clear by stating language - bytecount, prefixed with a #. \$\endgroup\$ Commented Nov 9, 2017 at 12:58
  • \$\begingroup\$ You can save six bytes by dropping j altogether: for(i=1;i<27;){console.log(String.fromCharCode(i+96).repeat(i++))} \$\endgroup\$ Commented Nov 13, 2017 at 14:46
  • \$\begingroup\$ @steenbergh thank you once again, your how kind you are to help me. \$\endgroup\$ Commented Nov 14, 2017 at 3:41
5
\$\begingroup\$

Japt, 9 7 bytes

Outputs an array of lines

;C¬Ëp°E 

Try it


Explanation

Split (¬) the lowercase alphabet (;C) to an array of characters, map over the array (Ë) and repeat (p) the current element by the current index (E) incremented (°) times.

\$\endgroup\$
1
  • \$\begingroup\$ Exactly what I had, except I used ®p°Y \$\endgroup\$ Commented Nov 9, 2017 at 2:27
5
\$\begingroup\$

Zsh (+ coreutils), 30 bytes

eval ';s+=_&&tr<<<$s _ '{a..z}

Attempt This Online!

Pure Zsh, 31 bytes

eval '<<<${(l:++i::'{a..z}:')}'

Attempt This Online!

\$\endgroup\$
5
\$\begingroup\$

OpTeX, 53 bytes

\fornum97..122\do{\fornum97..#1\do{\char#1}\par}\bye 

OpTeX is a modernized version of plain TeX. With the code above, the output is correct, but doesn't look good, as the generated document uses by default non mono-spaced font. It's better with \tt (typewriter font), but this adds 3 more bytes.

\tt\fornum97..122\do{\fornum97..#1\do{\char#1}\par}\bye 

Example

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Welcome to Code Golf Stack Exchange. Nice first submission! \$\endgroup\$ Commented Mar 3 at 16:06
5
\$\begingroup\$

MATL, 9 bytes

2Y2"@X@Y" 

Try it online!

Explanation

2Y2 % Push string 'abc...z' " % For each char in that string @ % Push current char X@ % Push iteration index (1-based) Y" % Run-length decoding: repeat char that many times % Implicit end. Implicit display 
\$\endgroup\$
2
  • \$\begingroup\$ Do you know why & can't be used to duplicate and transpose 2Y2? \$\endgroup\$ Commented Nov 9, 2017 at 14:27
  • \$\begingroup\$ @StewieGriffin & doesn't actually duplicate and transpose, although it sometimes produces the same result as that. What it does is modify the number of inputs/outputs of the next function. For example, if you use &+, the + function now takes one input instead of two, and outputs the sum of the input with itself transposed. But that's only because that's how + work with 1 input (same for =, > and some others) \$\endgroup\$ Commented Nov 9, 2017 at 15:55
3
\$\begingroup\$

R, 38 bytes

A relatively uninteresting answer. Iterate for i from 1 to 26, print the ith letter of the alphabet i times (with an implicit line break).

for(i in 1:26)print(rep(letters[i],i)) 

Try it online!

A more interesting approach might be to use something like the following:

cat(letters[(1:351*2)^.5+.5]) 

This gives us all the letters in the right amount, but no linebreaks. Perhaps someone smarter than me can figure out a way to use that to make a golfier answer.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ I'm not sure how to use your second approach, either, but I know that rep(letters, 1:26) is much shorter... \$\endgroup\$ Commented Nov 9, 2017 at 14:14
  • \$\begingroup\$ @Giuseppe Hah! Like I said, "someone smarter than me" is definitely needed. \$\endgroup\$ Commented Nov 10, 2017 at 0:02
3
\$\begingroup\$

Charcoal, 6 bytes

Eβ×ι⊕κ 

Try it online! Link is to verbose version of code. Explanation:

 κ Index ⊕ Incremented ι Character × Repeated β Lowercase letters E Map over each character Implicitly print each result on its own line 
\$\endgroup\$
3
\$\begingroup\$

Perl 5, 19 bytes

say$_ x++$"for a..z 

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Rust, 82 bytes

||for i in 1..27u8{println!("{}",((i+96) as char).to_string().repeat(i as usize))} 

I had hoped that it would've been a lot shorter, but explicitly converting/casting between types takes a lot of bytes :(

Try it online!

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I got 76 bytes: Try it online! \$\endgroup\$ Commented Nov 16, 2017 at 18:32
3
\$\begingroup\$

PHP, 47 46 bytes

for($c=a;$i<26;)echo" ",str_pad($c,++$i,$c++); 

or

for($c=a;$i<26;)echo str_pad(" ",++$i+1,$c++); 

Run with -nr or try it online.

\$\endgroup\$
3
\$\begingroup\$

J, 18 17 bytes

a.{~(#"0+&96)i.27 

Explanation:

 i.27 - list of integers 0 - 26 ( +&96) - adds 96 to the above list (starting offset of 'a') #"0 - copies the right argument left argument times {~ - select items from a list (arguments reversed) a. - the whole alphabet #"0 +&96 is a hook, which means that at first +96 is applied to the list i.27, resulting in a list 96, 97, 98... 122, then #"0 is applied to this result. So it is evaluated as ((i.27)#"0(96+i.27)){a: 

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Perl 6,  24  23 bytes

.say for 'a'..'z'Zx 1..* 

Try it

.say for 'a'..*Zx 1..26 

Try it

\$\endgroup\$
0
1
2 3 4 5

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.