67
\$\begingroup\$

Given no input, your task is to generate the following:

a
 b
  c
   d
    e
     f
      g
       h
        i
         j
          k
           l
            m
             n
              o
               p
                q
                 r
                  s
                   t
                    u
                     v
                      w
                       x
                        y
                         z

Nonvisually, your task is to generate each letter in the alphabet, with spaces before it equal to its position in the alphabet minus one.

If you print this, it must appear like the above. Extraneous whitespace that does not affect appearance, as well as a trailing newline, is allowed. You can use all lowercase, or all uppercase.

You may also return this from a function as per usual rules, either as a string with newlines, or a list of strings.

This is , so shortest answer in bytes wins!

\$\endgroup\$
  • \$\begingroup\$ Do the spaces need to be real ASCII spaces, or can I give output like a<VERTICAL-TAB>b<VERTICAL-TAB>c...? How about if there are some backspace characters in there too? As long as the visual result is the same? \$\endgroup\$ – Digital Trauma Jun 8 '17 at 23:30
  • \$\begingroup\$ @DigitalTrauma as long as it appears the same, I don't care what kind of whitespace you use. \$\endgroup\$ – Stephen Jun 8 '17 at 23:31
  • \$\begingroup\$ Can I use tabs instead of spaces? \$\endgroup\$ – user69335 Jun 9 '17 at 23:28
  • \$\begingroup\$ @yamboy1 hmm, probably not. Most tabs are set to a large number of spaces - if your diagonal looks like it has 4 spaces before the b, it won't look very diagonal. If it looks like the slope is ~-1 then it's fine. \$\endgroup\$ – Stephen Jun 9 '17 at 23:32
  • \$\begingroup\$ does not affecting appearance include having an extra leading space or 2? \$\endgroup\$ – MildlyMilquetoast Sep 11 '17 at 17:08

152 Answers 152

1
\$\begingroup\$

Recursiva, 16 15 bytes

{)"P+*-O}97' '}

Try it online!

Explanation:

{)"P+*-O}97' '}
{                - For each
 )               - lower-case alphabet yield 'abc...z'
  "              - Iteration command begin
   P             - Print
    +            - concatenate
     *-O}97' '   - Appropriate number of spaces
              }  - current alphabet (iterate)          
\$\endgroup\$
1
\$\begingroup\$

Pushy, 10 bytes

`a\x26`:"h32}

Where \x26 represents the literal byte 0x26.

Try it online!

`a\x26`         \ Push 'a' and 26
       :        \ Pop 26, loop that many times:
        "       \   Print the stack
         h      \   Increment the letter
          32}   \   Prepend a space
\$\endgroup\$
1
\$\begingroup\$

AWK, 40 bytes

BEGIN{for(;i<26;)printf"%"++i"c\n",i+96}

Try it online!

I didn't see an AWK solution, so here we go. Straightforward implementation, so more golfing may be possible.

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

Sincalr ZX81/Timex TS1000/1500 BASIC, ~45 tokenized BASIC bytes

 1 FOR I=CODE "A" TO CODE "Z"
 2 PRINT TAB (I-CODE "A");CHR$ I
 3 NEXT I

Some notes; without adding in more bytes to the listing, the standard output to the screen is 32 x 22 only, so when the screen fills, you will need to press C, and the keyword CONT will appear. You will then see the rest of the alphabet.

For those who want to see the Alphabet without having to manually enter CONT each time the last row is hit in the text area, this solution does it for you:

 1 FOR I=CODE "A" TO CODE "Z"
 2 PRINT AT CODE "+",I-CODE "A";CHR$ I
 3 SCROLL
 4 NEXT I

This version costs another 9 tokenized bytes though.

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

Pyth, 12 bytes

Fb26p*\ b@Gb

There's probably some way I can shave off a couple bytes, but I'm not quite sure yet.

Explanation:

Fb26p*\ b@Gb |
Fb26         | for b in range(26):
    p        |     print(
     *\ b    |           " "*b
         @Gb |                +G[b]

Note: G is initialized to "abcdefghijklmnopqrstuvwxyz"
\$\endgroup\$
1
\$\begingroup\$

MY-BASIC, 62 bytes

Anonymous function that takes no input and outputs to the console.

For i=0 To 25
For j=1 To i
Print" "
Next
Print Chr(65+I);
Next

Try it online!

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

Visual Basic .NET (Mono), 98 bytes

Declared Subroutine that that takes no input and outputs to the console.

Module M
Sub Main
Dim I
For I=0To 25
Console.WriteLine(Space(i)+Chr(65+I))
Next
End Sub
End Module

Try it online!

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

Momema, 51 bytes

m01*0w1-9 32 1+*1-1w0w=*1-9+97*0-9 10 0+1*0m=+-26*0

Try it online!

Explanation:

                                                              #  a = 0
m   0        #  label m0: jump past label m0 (no-op)          #  do {
1   *0       #            [1] = [0]                           #    b = a
w   1        #  label w0: jump past label w1                  #    while b != 0 {
-9  32       #            print chr 32                        #      print ' '
1   +*1-1    #            [1] = [1] - 1                       #      b -= 1
w   0        #  label w1: jump past label w0 (no-op)          #    [end-of-loop jump point]
w   =*1      #  label w2: jump past label w((2 + !![1]) % 3)  #    }
-9  +97*0    #            print chr 97 + [0]                  #    print chr(97 + a)
-9  10       #            print chr 10                        #    print '\n'
0   +1*0     #            [0] = [0] + 1                       #    a += 1
m   =+-26*0  #  label m1: jump past label m((1 + !![0]) % 2)  #  } while a != 0
\$\endgroup\$
1
\$\begingroup\$

Python 3, 51 bytes

print("\n".join(" "*n+chr(n+97)for n in range(26)))
\$\endgroup\$
  • \$\begingroup\$ you can avoid the join stuff by putting all this in a comprehensive list [print(" "*n+chr(n+97))for n in range(26)] \$\endgroup\$ – bobrobbob Jun 15 '18 at 18:03
1
\$\begingroup\$

Python 3, 74 64 63 Bytes

Saved ten bytes thanks to Caird

Saved one byte thanks to Stephen

Changed format to one-liner

Yes there are several Python 2 answers but how about one with Python 3?

for b in'abcdefghijklmnopqrstuvwxyz':print(' '*(ord(b)-97)+b)

First it makes a list of the alphabet then prints each letter but with n (Index of the value) spaces.

\$\endgroup\$
  • 1
    \$\begingroup\$ 64 bytes \$\endgroup\$ – caird coinheringaahing Feb 26 '18 at 21:12
  • \$\begingroup\$ 41 bytes \$\endgroup\$ – Jo King Feb 26 '18 at 23:33
  • \$\begingroup\$ I found there's an identical answer here \$\endgroup\$ – Jo King Feb 26 '18 at 23:54
  • \$\begingroup\$ Mine is a little different \$\endgroup\$ – AleXYX Feb 27 '18 at 14:16
  • \$\begingroup\$ b in 'abc -> b in'abc \$\endgroup\$ – Stephen Feb 28 '18 at 1:52
1
\$\begingroup\$

Japt -R, 7 bytes

;C¬ËiEç

Try it online!

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

Java (OpenJDK 8), 58 bytes

a->{for(char b=96;b++<122;a+=' ')System.out.println(a+b);}

Try it online!

I had no idea that you could make a for loop with a char variable... but here ya go! I’m pretty proud of my solution here, it may be my most golfed submission to date!

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

SNOBOL4 (CSNOBOL4), 72 65 bytes

E	&LCASE POS(X) LEN(1) . O @X	:F(END)
	OUTPUT =LPAD(O,X)	:(E)
END

Try it online!

swapping &UCASE for &LCASE would do the uppercase diagonal instead.

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

Add++, 43 36 bytes

D,f,@:^,32$yVVL97+
D,g,,26RBF€{f}
$g

Try it online!

Super suboptimal because I don't know what I'm doing

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

Python 2, 56 bytes

a=map(chr,range(65,91))
for i in a:print' '*a.index(i)+i
\$\endgroup\$
1
\$\begingroup\$

CJam, 13 bytes

26{_S*\'a+N}/

Try it online!

Explanation

26{        }/  for i in [0..25]:
    S*           puts ' ' * i
   _  \'a+       puts 'a' + i
          N      puts '\n'
\$\endgroup\$
1
\$\begingroup\$

PHP, 72 68 67 Bytes

Try it online!

Try it online (after @Titus review)

Try it online, last review. @Titus Strikes Back

Code, recursive function

function f($v=26){$v&&print str_pad("",$v).chr($v+96)." 
".f($v-1);}

Explanation

function f($v=26){
    $v&&print           # if $v not zero then print
    str_pad("",$v)     # pad spaces $v times
    .chr($v+96)     # concat the character at 96+$v 
    ."                 # concat a linebreak 
    ".f($v-1);          # call the function 
}
\$\endgroup\$
  • \$\begingroup\$ 1) You need no braces for the echo. 2) Try $l&&print instead of if($l>0)echo. 3) And please don´t use $l as a variable name. ;) \$\endgroup\$ – Titus Jun 17 '18 at 21:26
  • \$\begingroup\$ As always, thank you @Titus for your suggestions :D \$\endgroup\$ – Francisco Hahn Jun 19 '18 at 15:51
  • \$\begingroup\$ You´re welcome. print needs no parentheses. \$\endgroup\$ – Titus Jun 21 '18 at 7:08
1
\$\begingroup\$

Ahead, 31 30 bytes

"az"E>0\:'a-' l
  @?lj:oNW:k\<

Try it online!

-1 because leading spaces are allowed as long as everything is still aligned.

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

Ruby, 43 bytes

(0..25).each{|n|print" "*n;puts (n+97).chr}

Try it online!

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

Perl 6, 24 bytes

{map ' 'x$++~*,'a'..'z'}

Try it online!

Anonymous code block that returns a list of lines.

Alternatively,

{' 'x$++xx㉖Z~'a'..'z'}

Try it online!

behaves the same for the same bytecount.

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

dc, 28 bytes

97[ddPAP1+2z8*B-^+z27>M]dsMx

Try it online!

Outputs to stdout, makes lowercase letters

Explanation

P pops a number from the stack and outputs it as a base-256 byte stream. So I use some math to calculate each number (representing the appropriate string) "inductively" from the previous.

97        A literal, which P will print as ASCII 97 ('a')
[         Each loop starts with these two things true:
              The next number to Print is on top of the stack
              The stack depth is the # of times the loop has started (inclusive)
  dd        Make two copies: one to manipulate stack depth, one to print
  PAP       Print the number, then Print a newline (0x0A)
  1+        Increment the last digit (i.e., the letter)
  2z8*B-^+  Add the leftmost space, calculated as: 
                 32*(256^loop counter)  (because 32 = ' ')
               = 2^5*(2^8)^(z-2)        (z = stack depth = counter + 2)
               = 2^(8z-11)              (and to dc, 'B' pushes literal 11)
  z27>M     Repeat unless this was our 26th time through
]dsMx       End the loop, store it as a macro, and run it
\$\endgroup\$
1
\$\begingroup\$

C# (.NET Core), 71 58 53 52 bytes

for(var i='A';i<91;)WriteLine("".PadLeft(i-65)+i++);

Try it online!

Try it online!

Try it online!

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to PPCG! :) \$\endgroup\$ – Shaggy Jul 10 '18 at 8:51
  • 1
    \$\begingroup\$ Suggest putting the i++ at the very end to save a byte. \$\endgroup\$ – Jonathan Frech Jul 10 '18 at 10:57
  • \$\begingroup\$ Thanks @JonathanFrech I have included in my new approach \$\endgroup\$ – Anth12 Jul 10 '18 at 11:52
  • 1
    \$\begingroup\$ You can replace '[' with 91 for -1 byte \$\endgroup\$ – dzaima Jul 10 '18 at 23:45
1
\$\begingroup\$

><>, 35 Bytes

0::?\~1+:8c*+oao:55*)?;!
-10.\84*o1

Try it online

0                         initialise counter
 :                        make a copy to count spaces
  :?\                     only keep looping if greater than 0
    \84*o                 output a space
-        1                decrement the inner counter
 10.                      jump back to the start of the inner loop
     ~                    delete the inner loop counter
      1+                  increment the outer counter
        :8c*+o            make a copy of the counter, add 96, output the character
              ao          output a newline
                :55*)?;   terminate if the counter is now 26 or higher
                       !  skip the 0 at the start of the line
\$\endgroup\$
1
\$\begingroup\$

Red, 37 bytes

repeat n 26[print pad/left #"`"+ n n]

Try it online!

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

Dart, 65 bytes

f()=>List.generate(26,(i)=>String.fromCharCode(i+65).padLeft(i));

Try it online!

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

C++ (gcc), 50 48 bytes

[](){for(int c=0;printf("%*c\n",++c,c+97)-27;);}

Try it online!

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

MBASIC, 43 bytes

1 FOR I=0 TO 25:PRINT SPC(I)CHR$(97+I):NEXT

similar to Alphabet Staircase.

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

PowerShell Core, 27 bytes

'a'..'z'|%{' '*(+$_-97)+$_}

Try it online!

\$\endgroup\$
  • \$\begingroup\$ Hey Edwin, you can save an extra byte if you remove the + from the +$_-97 statement. Otherwise it's identical to my answer, see Here \$\endgroup\$ – KGlasier Dec 4 '18 at 18:42
1
\$\begingroup\$

Python 3 43 Bytes

for i in range(26):print(" "*i+chr(i+97))
\$\endgroup\$
1
\$\begingroup\$

Aheui (esotope), 183 bytes (65 chars; 59 Hangul, 6 ASCII)

발밦다빠따반두발따받타빠싺싻삮타빠바파자초
분벋서썩떠번벌또여cbtp어또벓범석터번벋
타타빠싹빠싺밨볺아멓히셕처오져퍼서써섟뻐서

Try it online!


"cbtp" in the middle of the code is just an abbreviation of my nickname, which is ignored by the interpreter and reduce 8 bytes by using ASCII, not Hangul.

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