30
\$\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

Scoring

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

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

93 Answers 93

14
\$\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\$
21
\$\begingroup\$

Python 2, 36 bytes

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

Try it online!

\$\endgroup\$
9
\$\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\$
  • \$\begingroup\$ 819⌶↑⎕A⍴¨⍨⍳26 \$\endgroup\$ – Adám Nov 8 '17 at 23:06
  • \$\begingroup\$ @Adám thanks! I tried all variations of / and \, completely ignored shape ⍨ \$\endgroup\$ – Uriel Nov 8 '17 at 23:12
  • \$\begingroup\$ You can remove the too. \$\endgroup\$ – Adám Nov 8 '17 at 23:40
  • \$\begingroup\$ @Adám but it would look uglier ⍨ \$\endgroup\$ – Uriel Nov 8 '17 at 23:42
  • \$\begingroup\$ Turn boxing on! \$\endgroup\$ – Adám Nov 8 '17 at 23:42
8
\$\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\$
  • \$\begingroup\$ *bows* Explanation for a noob? Does <$ repeat its first argument n times, where n is the length of its second argument? \$\endgroup\$ – totallyhuman Nov 8 '17 at 22:43
  • \$\begingroup\$ @totallyhuman There you go. Feel free to ask in Of Monads and Men if you have further questions. \$\endgroup\$ – Laikoni Nov 8 '17 at 22:52
  • \$\begingroup\$ There are some very interesting operators in Prelude... Thanks for the explanation! \$\endgroup\$ – totallyhuman Nov 8 '17 at 22:54
7
\$\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\$
7
\$\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\$
  • \$\begingroup\$ @JamesHolderness Yep. Thanks for catching that! \$\endgroup\$ – MildlyMilquetoast Nov 9 '17 at 2:30
7
\$\begingroup\$

Ruby, 32 30 bytes

-2 bytes thanks to @EricDuminil.

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

Try it online!

\$\endgroup\$
  • 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\$ – Eric Duminil Nov 9 '17 at 9:59
6
\$\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\$
6
\$\begingroup\$

Excel VBA, 38 bytes

Using Immediate Window. :)

[A1:A26]="=REPT(CHAR(96+ROW()),ROW())"
\$\endgroup\$
  • \$\begingroup\$ Ah. My bad. I thought it's Excel because I used Excel Functions using Immediate Window. \$\endgroup\$ – remoel Dec 19 '17 at 2:58
  • \$\begingroup\$ You can drop a byte by removing the terminal " \$\endgroup\$ – Taylor Scott Jan 30 '18 at 17:48
5
\$\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\$
5
\$\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\$
  • \$\begingroup\$ This is only 48 bytes by my count. \$\endgroup\$ – Jordan Nov 9 '17 at 1:21
  • 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\$ – Jordan Nov 9 '17 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\$ – Jordan Nov 16 '17 at 6:48
4
\$\begingroup\$

V, 9 bytes

¬az\ÓÎÛäl

Try it online!

Hexdump:

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

MATL, 9 bytes

2Y2"@X@Y"

Try it online!

Explanation

2Y2     % Push string 'abc...z'
"       % For char in that string each
  @     %   Push current char
  X@    %   Push iteration index (1-based)
  Y"    %   Run-length decoding: repeat char that many times
        % Implicit end. Implicit display
\$\endgroup\$
  • \$\begingroup\$ Do you know why & can't be used to duplicate and transpose 2Y2? \$\endgroup\$ – Stewie Griffin Nov 9 '17 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\$ – Luis Mendo Nov 9 '17 at 15:55
4
\$\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\$
4
\$\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\$
  • 1
    \$\begingroup\$ Øa×J should be enough. \$\endgroup\$ – Adám Nov 8 '17 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\$ – Jonathan Allan Nov 9 '17 at 0:02
  • \$\begingroup\$ program or function \$\endgroup\$ – Adám Nov 9 '17 at 0:53
4
\$\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\$
  • \$\begingroup\$ @StewieGriffin I was actually halfway commenting on your Octave answer on the coincidence of coming up with the same solution. \$\endgroup\$ – Sanchises Nov 9 '17 at 14:28
4
\$\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\$
  • \$\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\$ – steenbergh Nov 9 '17 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\$ – steenbergh Nov 13 '17 at 14:46
  • \$\begingroup\$ @steenbergh thank you once again, your how kind you are to help me. \$\endgroup\$ – NTCG Nov 14 '17 at 3:41
4
\$\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\$
  • \$\begingroup\$ Exactly what I had, except I used ®p°Y \$\endgroup\$ – ETHproductions Nov 9 '17 at 2:27
3
\$\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\$
3
\$\begingroup\$

Acc!!, 66 bytes

Count i while 26-i {
Count j while i+1-j {
Write 97+i
}
Write 10
}

Try it online!

With comments

# Loop i from 0 to 25
Count i while 26-i {
    # Loop j from 0 to i (inclusive)
    Count j while i+1-j {
        # Print a letter
        Write 97+i
    }
    # Print a newline
    Write 10
}
\$\endgroup\$
3
\$\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\$
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
    \$\begingroup\$ I'm not sure how to use your second approach, either, but I know that rep(letters, 1:26) is much shorter... \$\endgroup\$ – Giuseppe Nov 9 '17 at 14:14
  • \$\begingroup\$ @Giuseppe Hah! Like I said, "someone smarter than me" is definitely needed. \$\endgroup\$ – rturnbull Nov 10 '17 at 0:02
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\$
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\$
3
\$\begingroup\$

Octave, 25 24 bytes

['',tril((x=65:90)'+~x)]

Try it online!

Saved one byte thanks to Giuseppe who informed me that OP allows upper case letters.

Explanation:

Create a vector x with the ASCII-values of the upper case alphabet, and transpose it. Add the negated x (thus 26 zeros, in a row vector, in order to create a grid with (the ASCII-values of):

AAAA
BBBB
CCCC

Take the lower triangular matrix and convert to characters by concatenating with the empty string.

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

C (gcc), 48 bytes 50 bytes

Re-runnable version, as per cleblanc and Steadybox in the comments below.

s[9];main(i){for(;i<27;)puts(memset(s,i+95,i++));}

Try it online!

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

Japt, 17 16 11 bytes

-5 bytes thanks to Oliver

In ISO-8859-1

;26ÆCgX pXÄ

Not the best score, but I'm still a novice. Any suggestions are very welcome.

Outputs list of lines, as OP allowed. Link contains 3 bytes more for newlines.

Try it online!

;                      - Use string variables
 26                    - Literal 26
   Æ                   - For range 0..26
    C                  - Alphabet
     gX                -         . character at index X
        pXÄ            - Duplicate X+1 times
                       - End function (implicit)
\$\endgroup\$
  • 1
    \$\begingroup\$ Nice! 1oBÊÄ can be replaced by 26õ. You can save a couple more bytes by doing something like ;26ÆCgX pXÄ \$\endgroup\$ – Oliver Nov 10 '17 at 19:33
  • \$\begingroup\$ @Oliver How the heck I didn't see that 26 is shorter than alphabet length?! Thanks. Also, my bad I didn't found that o takes the f argument... \$\endgroup\$ – RedClover Nov 10 '17 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.