78
\$\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\$
6
  • \$\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\$ Jun 8, 2017 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, 2017 at 23:31
  • \$\begingroup\$ Can I use tabs instead of spaces? \$\endgroup\$
    – user69335
    Jun 9, 2017 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, 2017 at 23:32
  • \$\begingroup\$ does not affecting appearance include having an extra leading space or 2? \$\endgroup\$ Sep 11, 2017 at 17:08

170 Answers 170

1 2 3 4 5
6
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\$
4
  • 2
    \$\begingroup\$ Welcome to PPCG! :) \$\endgroup\$
    – Shaggy
    Jul 10, 2018 at 8:51
  • 1
    \$\begingroup\$ Suggest putting the i++ at the very end to save a byte. \$\endgroup\$ Jul 10, 2018 at 10:57
  • \$\begingroup\$ Thanks @JonathanFrech I have included in my new approach \$\endgroup\$
    – Anth12
    Jul 10, 2018 at 11:52
  • 1
    \$\begingroup\$ You can replace '[' with 91 for -1 byte \$\endgroup\$
    – dzaima
    Jul 10, 2018 at 23:45
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\$

MBASIC, 43 bytes

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

similar to Alphabet Staircase.

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

Python 3 43 Bytes

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

Pushy, 10 bytes

`a\0x1A;`:"32}h

Where \0x1A is the character 26, 'SUB'

Try it online!

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

Rockstar, 55 bytes

X's0
while X-26
cast X+97 into C
say " "*X+C
build X up

Try it here (Code will need to be pasted in)

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

Husk, 9 bytes

z:¡Θø…"az

Try it online! ¡Θø is the infinite list [""," "," "," ",...], and …"az is the lowercase alphabet.

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

Deadfish~, 827 bytes

{{i}}dddc{{d}i}iiic{ii}iic{iiiiii}iiiiiic{{d}i}iic{ii}iicc{{i}ddd}dddc{{d}i}ic{ii}iiccc{{i}ddd}ddc{{d}i}c{ii}iicccc{{i}ddd}dc{{d}i}dc{ii}iiccccc{{i}ddd}c{{d}i}ddc{ii}iicccccc{{i}ddd}ic{{d}i}dddc{ii}iiccccccc{{i}ddd}iic{{d}i}ddddc{ii}iicccccccc{{i}ddd}iiic{{d}i}dddddc{ii}iiccccccccc{{i}ddd}iiiic{{d}i}ddddddc{ii}ii{c}{{i}ddd}iiiiic{{d}}iiic{ii}ii{c}c{{i}ddd}iiiiiic{{d}}iic{ii}ii{c}cc{{i}dd}dddc{{d}}ic{ii}ii{c}ccc{{i}dd}ddc{{d}}c{ii}ii{c}cccc{{i}dd}dc{{d}}dc{ii}ii{c}ccccc{{i}dd}c{{d}}ddc{ii}ii{c}cccccc{{i}dd}ic{{d}}dddc{ii}ii{c}ccccccc{{i}dd}iic{{d}}ddddc{ii}ii{c}cccccccc{{i}dd}iiic{{d}}dddddc{ii}ii{c}ccccccccc{{i}dd}iiiic{{d}}ddddddc{ii}ii{cc}{{i}dd}iiiiic{{d}}{d}iiic{ii}ii{cc}c{{i}dd}iiiiiic{{d}}{d}iic{ii}ii{cc}cc{{i}d}dddc{{d}}{d}ic{ii}ii{cc}ccc{{i}d}ddc{{d}}{d}c{ii}ii{cc}cccc{{i}d}dc{{d}}{d}dc{ii}ii{cc}ccccc{{i}d}c

Try it online!

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

Julia 1.0, 31 bytes

@.println(" "^(0:25)*('a':'z'))

Try it online!

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

Elixir, 51 bytes

Enum.reduce ?a..?z,"",&(IO.puts([&2,&1])&&"#{&2} ")

Try it online!

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

Thunno d, \$ 12 \log_{256}(96) \approx \$ 9.88 bytes

AzA{s' *s+ZK

Attempt This Online!

Explanation

Az            # Lowercase Alphabet
  A{          # Enumerated for-loop:
    s         #  Swap so the index is on top
     ' *      #  Multiply " " by the index
        s+    #  Swap and add the character
          ZK  #  Print with a trailing newline
              # d flag stops implicit print at the end

Thunno N, \$ 12 \log_{256}(96) \approx \$ 9.88 bytes

Az26R' *ZZ.J

Attempt This Online!

Explanation

Az            # Lowercase Alphabet
  26R         # range(26)
     ' *      # Multiply " " by each number
        ZZ    # Zip together
          .J  # Join each inner list
              # N flag joins by newlines
              # Implicit output
\$\endgroup\$
1
\$\begingroup\$

SNOBOL4 (CSNOBOL4), 72 65 bytes

E	&LCASE O 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\$

Uiua 0.3.1, 17 bytes

+@ +×65⊃∘×⊞=..⇡26

See it in action

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

Python 3, 51 bytes

lambda:"\n".join(" "*i+chr(i+97)for i in range(26))

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Wait, why do you need lambda if you can print it with same count of bytes? \$\endgroup\$
    – Fmbalbuena
    Dec 30, 2023 at 16:45
  • \$\begingroup\$ hang on im going to try to golf it a bit \$\endgroup\$ Dec 30, 2023 at 16:52
1
\$\begingroup\$

Swift, 89 86 bytes

zip(0...,"abcdefghijklmnopqrstuvwxyz").map{print({String.init}()(" ",$0.0)+"\($0.1)")}
\$\endgroup\$
1 2 3 4 5
6

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.