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

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\$
  • \$\begingroup\$ If you’re fine with negative cells, you can save 4 bytes at the beginning \$\endgroup\$ – Jo King Dec 19 '17 at 2:41
2
\$\begingroup\$

Pyke, 5 bytes

G Foh*

Try it here!

       - o=0
G      -  alphabet
  F    - for i in ^:
     * -  ^ * v
   oh  -   (o++)+1
\$\endgroup\$
  • \$\begingroup\$ Is there supposed to be a space between G and F? \$\endgroup\$ – caird coinheringaahing Nov 8 '17 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 '17 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\$
  • \$\begingroup\$ Hey, cool to see you can skip chr$() in the call to String(). \$\endgroup\$ – steenbergh Nov 9 '17 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\$
  • \$\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 '17 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\$
  • \$\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\$ – MildlyMilquetoast Nov 9 '17 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\$ – MildlyMilquetoast Nov 9 '17 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\$ – James Holderness Nov 9 '17 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\$
  • \$\begingroup\$ Nice one. Recursion is hard in C#. I just found a solution in 57 bytes :p \$\endgroup\$ – aloisdg Nov 10 '17 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\$
  • \$\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 '17 at 22:48
  • \$\begingroup\$ OP allows list :) \$\endgroup\$ – aloisdg Nov 11 '17 at 9:14
  • \$\begingroup\$ That simplifies things, and shows me for not reading the question comments. \$\endgroup\$ – Ayb4btu Nov 11 '17 at 9:43
2
\$\begingroup\$

Jelly, 7 6 bytes

ØaxJŒg

Try it online!

Returns a list of lines

How it works

ØaxJŒg - Main link. No arguments
Øa     - Lower case alphabet
  x    - each repeated...
   J   - range(len) times (vectorises)
    Œg - group equal runs

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

ØaḊLСUZYṚ

Try it online!

\$\endgroup\$
  • \$\begingroup\$ 5 bytes \$\endgroup\$ – dylnan May 15 '18 at 5:07
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\$

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\$
  • \$\begingroup\$ You can save a byte by doing the s+=" " and print separately: n->{String s="";for(char i=96;++i<123;System.out.println(s.replace(' ',i)))s+=" ";} \$\endgroup\$ – Kevin Cruijssen Nov 9 '17 at 8:08
  • \$\begingroup\$ Also, kinda cheating imo due to two leading new-lines, but n->{String s="\n",r=s;for(char i=96;++i<123;r+=s.replace(' ',i))s+=" ";return r;} (81 bytes) would also be possible. OP said in the comments trailing/leading spaces/new-lines are allowed, but I'm not sure if more than 1 is allowed. \$\endgroup\$ – Kevin Cruijssen Nov 9 '17 at 8:18
  • 1
    \$\begingroup\$ Sorry for all the comments, but this time without leading new-lines and shorter (and uppercase): n->{String r="";for(char c=64,i;++c<91;r+="\n")for(i=64;i++<c;r+=c);return r;} (78 bytes) Got inspired by an old answer of mine. :) \$\endgroup\$ – Kevin Cruijssen Nov 9 '17 at 9:14
  • \$\begingroup\$ @KevinCruijssen It's only fair to have provided many answers: I reckon I often do it as well ;-) Thanks for this golf! \$\endgroup\$ – Olivier Grégoire Nov 9 '17 at 9:45
  • \$\begingroup\$ @Oliver I worked on trying to make it shorter for quite some time and was unable to. However I thought you might find this interesting. Incrementing starting at 97 (ASCII for 'a') does not shorten the byte count :( I could only get it down to 79 on my best attempt: a->{for(int i=97,j=96;i<123;)System.out.printf("%c",j++<i?i:106-(j=j-++i+96));} \$\endgroup\$ – DevelopingDeveloper Dec 19 '17 at 21:07
2
\$\begingroup\$

Kotlin, 56 bytes

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

Try it online!

\$\endgroup\$
  • \$\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 '17 at 0:06
  • \$\begingroup\$ 48 bytes as a function. \$\endgroup\$ – ovs Nov 26 '17 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 '17 at 21:28
  • \$\begingroup\$ @ovs Nice! Your solution is much better than mine. I'll vote yours. \$\endgroup\$ – alves Nov 26 '17 at 21:43
  • \$\begingroup\$ @alves No, I wasn't. Sorry for the confusion. \$\endgroup\$ – Steadybox Nov 26 '17 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\$
  • \$\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 '17 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 '17 at 21:50
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\$
1
\$\begingroup\$

Tcl, 80 bytes

set a 97;time {time {puts -nonewline [format %c $a]} [incr i];puts "";incr a} 26

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Funky, 42 bytes

fori=1i<27i++print("a".char(96+i)::rep(i))

Try it online!

\$\endgroup\$
1
\$\begingroup\$

QBIC, 23 bytes

[26|[a|?chr$(a+96)';`]?

Explanation

[26|   FOR a = 1 TO 26
[a|      FOR b = 1 TO a
?chr$(     PRINT the character
a+96)         a, or b, or c depending on outer loop
';`           and suppress new-lines, tabs etc
]          NEXT, for this character (a, bb, ccc)
?          PRINT a newline between a, bb, ccc....
       NEXT on outer loop added implicitly
\$\endgroup\$

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.