37
\$\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\$ Nov 8, 2017 at 22:19
  • 5
    \$\begingroup\$ Can we use the uppercase alphabet instead? \$\endgroup\$
    – Uriel
    Nov 8, 2017 at 22:20
  • 9
    \$\begingroup\$ I was missing alphabet challenges! (but don't let Leaky Nun know) \$\endgroup\$
    – Luis Mendo
    Nov 8, 2017 at 22:32
  • 11
    \$\begingroup\$ I worked very hard checking if it was a dupe and apparently it isn't \$\endgroup\$
    – Blue
    Nov 8, 2017 at 22:35
  • 5
    \$\begingroup\$ @totallyhuman that's up to you. \$\endgroup\$ Nov 8, 2017 at 23:31

108 Answers 108

3
\$\begingroup\$

Brain-Flak, 107 bytes

((((()()()){}){}()){}){(({})){({}<(({})<({}((((()()()()){}){}){}){})>)>[()])}{}({}<((()()()()()){})>[()])}

Try it online!

This is 106 bytes of code, and +1 byte for the -A flag, which enables ASCII output.

Explanation:

#Push 26
((((()()()){}){}()){})

#While True...
{

    #Duplicate A
    (({}))

    #While True...
    {
        #Grab the value of A...
        ({}<

            #Make a duplicate of B (on the first loop, B == A)
            (({})<

                #Push B + 
                ({}

                #64 (ASCII 'A' - 1)
                ((((()()()()){}){}){}){})

            #Then push B on top of all of that
            >)

        #Push A - 1 on top of all of that
        >[()])

    #Endwhile, pop the loop counter
    }{}

    #Underneath A,
    ({}<

        #Push 10
        ((()()()()()){})

    # Then Push A - 1
    >[()])

#Endwhile
}
\$\endgroup\$
3
\$\begingroup\$

Brainfuck, 107 104 94 Bytes

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

How it works:

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

Stores 26 on the second cell, 65 on the third cell, 10 on the sixth cell, and 1 on the fourth, leaving the pointer on the fourth (Saved 3 13 bytes by making 26, 10, and 97 65 at the same time).

[<]>

Moves the pointer back to the start.

Now we're ready to get started!

[                       | While the first cell is non-zero (so 26 times)
>>                      | Move to cell 3
    [                   | While cell 3 is non-zero
        <.>>+<-         | Print cell 2, increment cell 4, and decrement cell 3
    ]                   |
    >>.<<               | Move to cell 5 and print it (new line), then return
    <+>+>               | Increment cells 2 and 3, and move to 4
    [<+>-]              | Add the value at 4 to 3
<<<-                    | Decrement cell 1
]                       |

The important part is that cell 3 stores the number of times to print a letter. Each time a letter is printed, the value at 3 is moved to 4 and increased by 1, so that the next number is printed one more time than the last.

Side Note:

I'm completely new to brainfuck, so I wouldn't be surprised if this could be improved. However, I was also surprised by how fun brainfuck is to write, as well as by how easy it was to write, when compared with what I had imagined.

I would definitely recommend learning brainfuck to any bored programmers out there ;)

\$\endgroup\$
1
  • \$\begingroup\$ If you’re fine with negative cells, you can save 4 bytes at the beginning \$\endgroup\$
    – Jo King
    Dec 19, 2017 at 2:41
3
\$\begingroup\$

Java (OpenJDK 8), 74 bytes

n->{for(int i=1,j=0;i<27;)System.out.printf("%c",j++<i?96+i:10+(j-=++i));}

Try it online!

6 bytes saved thanks to @KevinCruijssen

Explanations

n->{                      // Lambda, unused parameter
 for(int i=1,j=0;i<27;)   // Loop from 1 to 26 included
  System.out.printf("%c", // Print a character
   j++<i                  // Do we need to print a letter or a new line?
    ?96+i                 // It's a character, construct it.
    :10+(j-=++i)          // It's a new line, increment i and reset j to 0.
  );
}
\$\endgroup\$
7
2
\$\begingroup\$

Pyke, 5 bytes

G Foh*

Try it here!

       - o=0
G      -  alphabet
  F    - for i in ^:
     * -  ^ * v
   oh  -   (o++)+1
\$\endgroup\$
2
  • \$\begingroup\$ Is there supposed to be a space between G and F? \$\endgroup\$ Nov 8, 2017 at 22:42
  • \$\begingroup\$ That's just in the readable version, in the link, that's changed into a single byte and that's just the 2 byte representation I've used \$\endgroup\$
    – Blue
    Nov 8, 2017 at 23:14
2
\$\begingroup\$

VBA, 33 Bytes

Anonymous VBE immediate window function that outputs to the VBE immediate window

For i=1To 26:?String(i,96+i):Next
\$\endgroup\$
1
  • \$\begingroup\$ Hey, cool to see you can skip chr$() in the call to String(). \$\endgroup\$
    – steenbergh
    Nov 9, 2017 at 13:04
2
\$\begingroup\$

C# (.NET Core), 78 bytes

n=>{var s="";for(int i=1;i<27;)s+=new string((char)(i+96),i++)+'\n';return s;}

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Mathematica, 33 bytes

Alphabet[][[#]]~Table~#&~Array~26

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Stacked, 14 bytes

[26~>:96+chr*]

Try it online!

Pushes a list of lines to the stack.

Explanation

[26~>:96+chr*]
[            ]  anonymous function, takes no arguments
 26~>           range from 1 to 26
     :96+       push range from 97 to 122 (97..122')
         chr    convert each of these to a char ('a'..'z')
            *   repeat each char by the former amount ('a' 'bb' 'ccc' ...)
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

C (gcc), 53 bytes

i,j;f(){i=i-putchar(j++-i?96+i:(j=!++i)+10)-16&&f();}

Prints a leading newline. Has undefined behaviour, but works with gcc...

Try it online!

C, 54 bytes

j;main(i){for(;i<27;)putchar(j++-i?96+i:(j=!++i)+10);}

Try it online!

C, 54 bytes

i,j;f(){putchar(j++-i?96+i:(j=!++i)+10);(i%=27)&&f();}

Prints a leading newline.

Try it online!

C, 56 bytes

main(i,j){for(;i<27;)for(j=++i;j--;)putchar(j?95+i:10);}

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ j;main(i){for(;i<28;putchar(j?95+i:10))j=j?j-1:i++;} (52 bytes) almost works. \$\endgroup\$
    – Steadybox
    Nov 9, 2017 at 1:19
2
\$\begingroup\$

Japt, 9 bytes

;C£RiXpYÄ

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Befunge, 37 35 bytes

:"a"+:>,#:\:#->#1_55+,$"`"-:55*`#@_

Try it online!

Explanation

The program starts with an implicit zero on the stack, representing the repeat count (off by 1).

:"a"+                                Duplicate the count and convert it to a character.
     :                               Duplicate the character prior to writing it out.

      >                              Start the output loop.
       ,                             Write the duped character to stdout.
          \                          Swap the count to the top of the stack.
           :  >  _                   Duplicate it and check if zero, returning left if not.
             -  1                    Decrement the count.
          \                          Swap the character back to the top.
         :                           Duplicate it prior to writing it out again.
      >                              Repeat the loop.

                 _                   If the count reached zero, we continue right.
                  55+,               Output a linefeed.
                      $              Drop the zero count.
                       "`"-          Convert the character to a numeric count and increment.
                           :55*`     Check if greater than 25.
                                #@_  If so, then terminate, else wrap back to the start.
\$\endgroup\$
3
  • \$\begingroup\$ I feel like this could almost be golfed further by combining the ` before the loop with the ` inside the loop, but it screws too much up \$\endgroup\$ Nov 9, 2017 at 1:49
  • \$\begingroup\$ Whoops! Yeah, I meant the `\`s. Apparently I have to escape them. EDIT: I have no clue how code snippets in comments work \$\endgroup\$ Nov 9, 2017 at 2:26
  • \$\begingroup\$ @MistahFiggins Did a bit of fiddling to try and combine the swaps, and while that didn't help with the size of the inner loop, it did enable me to get rid of the 2+ increment at the start, saving a couple of bytes. So thanks for pushing me to look at it again. \$\endgroup\$ Nov 9, 2017 at 4:33
2
\$\begingroup\$

Retina, 20 bytes

:`
a
{2`
$`
T:`_l`l_

Try it online!

Prints a couple of trailing linefeeds.

Explanation

:`
a

Initialise the string to a and print it.

{2`
$`

The { tells Retina to loop the remainder of the program until it fails to change the string. The stage itself duplicates the first character.

T:`_l`l_

This increments all letters using transliteration and prints the result.

\$\endgroup\$
2
\$\begingroup\$

Brachylog, 7 bytes

Ại₁j₎ẉ⊥

Try it online!

Explanation

Ạ         The alphabet string "abcdefghijklmnopqrstuvwxyz"
 i₁       A couple: [a letter of the alphabet, its index (1-indexed) in it]
   j₎     Juxtapose that letter as many times as its index
     ẉ    Write followed by a linebreak
      ⊥   False: try another couple of [letter, index]
\$\endgroup\$
2
\$\begingroup\$

Elixir, 47 bytes

for x<-?a..?z,do: IO.puts List.duplicate x,x-96

Try it

\$\endgroup\$
2
\$\begingroup\$

JavaScript, 65 bytes

for(x=0;x<26;)console.log(String.fromCharCode(x+97).repeat(++x));

old:

for(x=0;x<26;x++)console.log((function p(a,b){return b==0?a:a+p(a,--b);})(String.fromCharCode(97+x),x));
\$\endgroup\$
2
\$\begingroup\$

Common Lisp, 65 bytes

(dotimes(a 26)(format t"~v@{~a~:*~}~%"(1+ a)(code-char(+ a 97))))

Try it online!

\$\endgroup\$
2
\$\begingroup\$

C# (.NET Core), 84 bytes

()=>{return A(1);string A(int n)=>new string((char)(n+96),n)+(n<26?"\n"+A(++n):"");}

Try it online!

A recursive approach using a local function (given no inputs were allowed).

UnGolfed

()=>{
    return A(1);
    string A(int n) => new string((char)(n+96), n) +
                       (n < 26? "\n" + A(++n) : "");
}
\$\endgroup\$
1
  • \$\begingroup\$ Nice one. Recursion is hard in C#. I just found a solution in 57 bytes :p \$\endgroup\$
    – aloisdg
    Nov 10, 2017 at 15:39
2
\$\begingroup\$

Underload, 62 bytes

()(::(.)~^(.):*:*:*:*:*::***( )*~^S(
)S(:)~*(*)*):*::*:*::***^

Try it online!

This is really stretching the limits of what's allowed.

It outputs a list of lines represented by strings (allowed by the OP), where the strings are lists of bytes (allowed by meta consensus), where the bytes are given in unary (also allowed by meta consensus).

The result is... well, see for yourself.

\$\endgroup\$
2
\$\begingroup\$

C# (.NET Core), 57 bytes

57 bytes with a a trailling line

()=>new int[27].Select((_,i)=>new string((char)(i+96),i))

59 bytes without a trailling line

()=>new int[26].Select((_,i)=>new string((char)(i+++97),i))

Try it online!

I am using using System.Linq;

  • The int[x].Select() can be found here.
\$\endgroup\$
3
  • \$\begingroup\$ Nicely done. I'm going to have to learn this Select trick. (I would have thought it would need to be wrapped in string.Join("\n",...) though.) \$\endgroup\$
    – Ayb4btu
    Nov 10, 2017 at 22:48
  • \$\begingroup\$ OP allows list :) \$\endgroup\$
    – aloisdg
    Nov 11, 2017 at 9:14
  • \$\begingroup\$ That simplifies things, and shows me for not reading the question comments. \$\endgroup\$
    – Ayb4btu
    Nov 11, 2017 at 9:43
2
\$\begingroup\$

CJam, 13 bytes

26{)_96+c*N}%

Explanation:

26             e# push 26
  {        }%  e# for n in 0 .. 25:
   )           e#   increment
     96+       e#   add 96
        c      e#   convert to character
    _    *     e#   repeat that character n+1 times
          N    e#   add a newline
\$\endgroup\$
2
\$\begingroup\$

Kotlin, 56 bytes

for(c in 'a'..'z'){for(j in 0..c-'a')print(c);println()}

Try it online!

\$\endgroup\$
5
  • \$\begingroup\$ I don't understand. Isn't this a valid full Kotlin program? Just drop it on a .kts file and it will run as is. \$\endgroup\$
    – alves
    Nov 26, 2017 at 0:06
  • \$\begingroup\$ 48 bytes as a function. \$\endgroup\$
    – ovs
    Nov 26, 2017 at 14:01
  • \$\begingroup\$ @Steadybox are you are aware that Kotlin can run in script mode, in which case it doesn't need to declare the main function? \$\endgroup\$
    – alves
    Nov 26, 2017 at 21:28
  • \$\begingroup\$ @ovs Nice! Your solution is much better than mine. I'll vote yours. \$\endgroup\$
    – alves
    Nov 26, 2017 at 21:43
  • \$\begingroup\$ @alves No, I wasn't. Sorry for the confusion. \$\endgroup\$
    – Steadybox
    Nov 26, 2017 at 22:06
2
\$\begingroup\$

Befunge 2x24 = 48 Bytes

I know the other befunge answer has me solidly beat, but I thought I'd post my solution anyway, as it's interesting, since it's partially self-modifying.

"z`"-:!_> 10g\v v!:_0# p
g01+55$_^#!:-1<@_,1^01-1

Try It Online

How it works

"?`"-:!

Gets how many times to iterate. (The question mark represents the current letter)

        _> 10g\v
        _^#!:-1<

Adds the iteration size*char into the stack.

                   _0# p
g01+55$_           ^01-1 

Pops the excess character and adds a newline. Gets the current character from 1,0 and decrements it, putting back at 1,0

"?`"-:!_           _0# p

Now the ? inside the quotes has been decremented. Once it has run through all the letters it runs backwards from the underscore, which was the tricky part. ! inverts the excess 0 to a 1, which is duplicated and subtracted from itself, turning it back to a 0. The 0 is put at (97,97) thanks to the backticks inside the quotes and the put command. This leaves just the original iteration size, which is 0, when it hits the underscore, pushing the pointer left.

                v!:_
               @_,1^

Prints out the whole stack, which at this point is a newline separated alphabet staircase.

\$\endgroup\$
2
\$\begingroup\$

Kotlin, 37 bytes

{(1..26).map{"${'`'+it}".repeat(it)}}

Try it online!

Returns a List of Strings

\$\endgroup\$
2
  • \$\begingroup\$ This is a nice solution but is it ok to just return a list of Strings, without printing them? I'm still new to the code golf rules... \$\endgroup\$
    – alves
    Nov 26, 2017 at 21:47
  • \$\begingroup\$ @alves The OP verified this in a comment. Usually these rules should be in the post itself, but it is always useful to look in the comments. \$\endgroup\$
    – ovs
    Nov 26, 2017 at 21:50
2
\$\begingroup\$

brainfuck, 70 59 bytes

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

Try it online!

-<--[[<+>->----<]++>]<-<-<<
Sets the tape up as:
     254
     9    Newline (10-1)
     230' Loop counter (-26)
     114  
     65   Character (A)
     1    Repeat counter
[ Loop 26 times
   >>>[-<.>>+<]   Print the character repeat counter times while preserving the counter
   >[-<+>]        Restore counter
   <[+<]          Increment everything
   >->.->         Print a newline
]
\$\endgroup\$
2
\$\begingroup\$

Jelly, 7 6 5 bytes

Øax"J

Try it online!

-1 byte thanks to dylnan

Returns a list of lines

How it works

Øax"J - Main link. No arguments
Øa    - Lower case alphabet
  x"  - each character repeated...
    J - range(len) times (vectorises)

An alternative (which I prefer, but is longer):

ØaḊLСUZYṚ

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ 5 bytes \$\endgroup\$
    – dylnan
    May 15, 2018 at 5:07
2
\$\begingroup\$

Java (JDK), 68 bytes

n->{for(var i='`';i++<'z';)System.out.println((i+"").repeat(i-96));}

Try it online!

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Congrats on using newer API to beat my score! :-) \$\endgroup\$ Sep 26, 2021 at 21:00
  • \$\begingroup\$ Oh I didn't realize String::repeat was new in the API. Sorry then. Your solution was a lot more creative and harder though ;) \$\endgroup\$
    – 0xff
    Sep 27, 2021 at 10:49
  • 2
    \$\begingroup\$ It's fine! String::repeat comes from Java 11 which is from September 2018, 1 year before my answer, and it's always OK to take the full tools at your disposal to golf, that's what I always advocate, so your answer is perfect in that regards, don't be sorry :D \$\endgroup\$ Sep 27, 2021 at 11:25
2
\$\begingroup\$

Vyxal j, 6 bytes

ka¨2›*

Try it Online!

How?

ka¨2›*
ka     # Push the lowercase alphabet
  ¨2   # Map with indices (pushes letter and index)
    ›  # Increment the index to make it one-indexed
     * # Repeat the letter that many times

Also 6 bytes:

kaf:ż*

Try it Online!

How?

kaf:ż*
ka     # Push the lowercase alphabet
  f    # Convert to list of characters
   :   # Duplicate it
    ż  # Push length range [0, length)
     * # Repeat each letter that many times
\$\endgroup\$
1
\$\begingroup\$

Pyth, 7 bytes

.e*hkbG

Try it online!

Outputs a list of lines. If that's not allowed, add a j to the start and let me know to add one byte to the count!


.e*hkbG  Full program - outputs to stdout
.e       map over
      G  the alphabet,
  *  b   repeating each letter
   hk    according to its index+1
\$\endgroup\$
1
\$\begingroup\$

JavaScript, 113 bytes

(function(){var i=0,j=0,s;while(++i<=26){s="";j=0;while(++j<=i)s+=String.fromCharCode(96+i);console.log(s);}})();

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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