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

170 Answers 170

2
\$\begingroup\$

Canvas, 2 bytes

z\

Try it here!

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

Stax, 6 bytesCP437

åuvÉ◄┘

Try it online!

Explanation

Uses the unpacked format to explain.

Vam]i^)
Va         "abcdefghijklmnopqrstuvwxyz"
  m        For each letter, execute the rest of the program
               Output the result on individual lines
   ]       Change the letter to a single-letter string
    i^     Current loop index+1
      )    Pad the string to given length
\$\endgroup\$
2
\$\begingroup\$

K4, 18 bytes

Solution:

-1(-1-!26)$'$.Q.a;

Example:

q)k)-1(-1-!26)$'$.Q.a;
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

Explanation:

Left-pad the alphabet:

-1(-1-!26)$'$.Q.a; / the solution
-1               ; / print to STDOUT, swallow return
             .Q.a  / "abcdefghijklmnopqrstuvwxyz"
            $      / string, basically 1#'
          $'       / pad ($) each-both
  (      )         / do together
      !26          / range 0..25
   -1-             / subtract from -1

Bonus:

15 bytes returning a list of strings rather than printing to STDOUT:

(-1-!26)$'$.Q.a
\$\endgroup\$
2
\$\begingroup\$

Pepe, 79 76 56 bytes

Way better, faster algorithm which performs like 3 times less operations. And saves 3 bytes. Now even more, because Pepe supports flags - no more unnecessary item movement!

REeEEEEeEErEeEEeeeeEREEreeereeErEEEEERrEeeEeeeeerEEEeRee

Try it online!

Explanation

REeEEEEeEE   # push "{" to R
rEeEEeeeeE   # push "a" to r

REE # label "{"

  reee # print stack contents
  reeE # print newline

  rEEEEE       # increment the letter
  R rEeeEeeeee # prepend a space
  rEEEe        # r pointer to end

Ree # goto "{" if the letter didn't reach "{" yet
\$\endgroup\$
0
2
\$\begingroup\$

QBasic 1.1, 35 bytes

FOR S=0TO 25
?SPC(S)CHR$(S+97)
NEXT

-8 thanks to DLosc.

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

Z80Golf, 19 bytes

00000000: c661 ff3e 0aff 3e20 0c41 ff10 fd79 fe1a  .a.>..> .A...y..
00000010: 20ee 76                                   .v

Try it online!

Disassembly:

restart:
  add 'a'
  rst $38
  ld a, '\n'
  rst $38
  ld a, ' '
  inc c
  ld b, c
k:rst $38
  djnz k
  ld a, c
  cp 26
  jr nz, restart
  halt
\$\endgroup\$
2
\$\begingroup\$

Pascal (FPC), 56 bytes

Well, I found 2 programs with the same number of bytes.

Program 1:

var c:char;begin for c:='a'to'z'do writeln(c:ord(c))end.

Try it online!

Explanation:

var c:char; //declare c as char variable
begin
  for c:='a' to 'z' do //iterate in a loop, c is getting values from a to z
    writeln(c          //write the current character followed by a newline
             :         //with a width of
              ord(c))  //ASCII code of the current character
                       //(using extraneous whitespace allowed by the challenge)
end.

Program 2:

var i:byte;begin for i:=97to 122do writeln(chr(i):i)end.

Try it online!

Explanation:

var i:byte; //declare i as integer variable in range 0..255
begin
  for i:=97 to 122 do //iterate in a loop, i starts from 97 and is incremented in each iteration
    writeln(chr(i)    //write character which ASCII codepoint is the current value of i
                  :   //with a width of
                   i) //current value of i
                      //(using extraneous whitespace allowed by the challenge)
end.
\$\endgroup\$
2
\$\begingroup\$

brainfuck, 74 bytes

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

Try it online!

Explanation

++++++++[->+++>+>++++++++>++++<<<<]>++>++ Initialize tape:
26(letter count) 10(lf) 64("A" minus 1) 32(" ") 0(space count) 0(temp) 

<[                                        for each letter count
  -                                       decrement letter count
  >>>>[-<.>>+<]                           for each space count print space and move value to temp
  +                                       increment space count
  >[-<+>]                                 add temp to space count
  <<<+.                                   increment and print letter
  <.                                      print lf
  <                                       go to count
]
\$\endgroup\$
2
\$\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\$
2
\$\begingroup\$

C++ (gcc), 50 48 bytes

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

Try it online!

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

PowerShell Core, 27 bytes

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

Try it online!

\$\endgroup\$
1
  • \$\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
    Commented Dec 4, 2018 at 18:42
2
\$\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\$
2
\$\begingroup\$

Attache, 21 bytes

Output[sp*0:25+$a:$z]

Try it online!

Explanation

Output[sp*0:25+$a:$z]
Output[             ]     write each entry as a line to stdout:
       sp*0:25                spaces repeated 0 to 25 times (array)
              +$a:$z          each followed by a letter from "a" to "z"

Alternatives

22 bytes: Output[" "*0:25+$a:$z]

23 bytes: Print=>(" "*0:25+$a:$z)

24 bytes: Print@{_*sp+NTS@_}=>0:25

31 bytes: Print@&PadLeft=>Zip[$a:$z,1:26]

35 bytes: {Print@_If[$z!in_,$[sp+Succ@_]]}@$a

37 bytes: {Print@_If[_@-1/=$z,$[sp+Succ@_]]}@$a

37 bytes: Print@&PadLeft=>Zip[Chars@alpha,1:26]

40 bytes: Output!ZipWith[PadLeft,Chars@alpha,1:26]

40 bytes: Print=>ZipWith[PadLeft,Chars@alpha,1:26]

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

05AB1E, 8 4 bytes

₂A3Λ

Try it online!

-4 bytes thanks to @ovs.

₂     # push 26
 A    # push "abcdefghijklmnopqrstuvwxyz"
  3   # push 3
   Λ  # draw a line on an ASCII canvas that is 26 characters long, uses lowercase letters in order for characters, and goes in direction 3 (southeast)
\$\endgroup\$
1
  • \$\begingroup\$ You can use the canvas for 4 bytes: ₂A3Λ \$\endgroup\$
    – ovs
    Commented Sep 29, 2020 at 16:02
2
\$\begingroup\$

Python 3.8 (pre-release), 60 bytes

n=0
for l in"abcdefghijklmnopqrstuvwxyz":print(" "*n+l);n+=1

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ This is shorter without an assignment expression: Try it online! \$\endgroup\$
    – pxeger
    Commented Dec 9, 2021 at 15:05
  • \$\begingroup\$ @pxeger Fixed.. \$\endgroup\$ Commented Dec 9, 2021 at 15:07
  • \$\begingroup\$ Actually, I was wrong; leading spaces are allowed. But it's still shorter this way. \$\endgroup\$
    – pxeger
    Commented Dec 9, 2021 at 15:08
2
\$\begingroup\$

JavaScript (Node.js), 63 bytes

for(i=0;++i<27;){console.log(" ".repeat(i)+(i+9).toString(36))}

Try it online!

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

Vyxal, 15 14 bytes

₄ʁ(|kaniðn*p,)

Try it Online!

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

Cheddar, 31 bytes

->(|>26).map(n->' '*n+@"(n+97))

Try it online!

Defines a niladic lambda which returns a list of strings.

Full program, 42 bytes

print(|>26).map(n->' '*n+@"(n+97)).asLines

Try it online!

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

Javascript, 75 72 bytes

_=>[...'abcdefghijklmnopqrstuvwxyz'].map((n,i)=>' '.repeat(i)+n).join`
`

3 bytes thanks to Stephen S.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You can save some bytes with backticks and a literal newline for your join: jsfiddle.net/pL1onLqb \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 2:21
  • \$\begingroup\$ Save a byte using some ES8: ''.padEnd(i)+n \$\endgroup\$
    – Shaggy
    Commented Jun 8, 2017 at 7:08
  • 1
    \$\begingroup\$ Also, outputting the array would seem to be permissible, in which case you can drop the join. \$\endgroup\$
    – Shaggy
    Commented Jun 8, 2017 at 9:51
1
\$\begingroup\$

Braingolf, 24 bytes

V# 7-#
R#a[R!&@# >1+v!@]

Try it online!

Explanation

V# 7-#\nR#a[R!&@# >1+v!@]
V                          Create stack2 and switch to it
 # 7-                      Push 32 and subtract 7
     #\n                   Push newline
        R                  Return to stack1
         #a                Push lowercase a
           [............]  Do-while loop, uses stack2 for loop counting
                           Will run 26 times
            R              Return to stack1
             !&@           Print entire stack without popping
                # >        Push space and move it to start of stack
                   1+      Increment letter
                     v     Switch to stack2
                      !@   Print newline
\$\endgroup\$
1
\$\begingroup\$

Aceto, 28 bytes

L 'XcIo
p*=`MILp
aM{'&n
'@dL

Explanation:

First of all, we put the character a in our quick storage ('aM) and set a catch point (@). We then duplicate the top stack element (initially a zero) and load both from quick storage and from the character literal {. These characters are then tested for equality, in which case we exit (=`X).

Otherwise we push a space and multiply it with the previously duplicated stack element (used as a counter). This is then printed, which prints nothing the first time this is run, a single space the second time, and so on (' *p).

We load the current character again and print it, then we load it again, convert it to the number of its codepoint, increment it, convert it to a character again and memorize it (LpLoIcM). Finally, we increment our counter, print a newline, and jump to the catch mark (In&).

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

S.I.L.O.S, 101 bytes

a=26
c=97
lblb
i=0
GOTO d
lblc
print  
b-1
i+1
lbld
if b c
b=i+1
printChar c
printLine
a-1
c+1
if a b

Try it online!

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

Mathematica, 42 bytes

Table[" "~Table~i<>Alphabet[][[i]],{i,26}]

outputs a list of strings

\$\endgroup\$
2
  • \$\begingroup\$ A list of string format is allowed, so you don't need Column@, save 7 bytes. You can save another byte with " "~Table~i. Thanks for letting me know about Alphabet[]. \$\endgroup\$
    – user202729
    Commented Jun 8, 2017 at 14:38
  • \$\begingroup\$ I didn't notice it... thanks for -8bytes \$\endgroup\$
    – ZaMoC
    Commented Jun 8, 2017 at 14:52
1
\$\begingroup\$

LOGO, 47 bytes

Can be tried with FMSLogo. Unfortunately the version at Turtle Academy does not work well.

for[i 0 25][repeat :i[type "\ ]show char 65+:i]
\$\endgroup\$
1
\$\begingroup\$

Oracle SQL, 62 bytes

SELECT LPAD(CHR(LEVEL+96),LEVEL) FROM DUAL CONNECT BY LEVEL<27
\$\endgroup\$
1
\$\begingroup\$

Micro, 35 bytes

64:i {i1+:i i c:\
64 26+i=if(,a)}:a a
\$\endgroup\$
1
\$\begingroup\$

Pyke, 6 bytes

G Foh-

Try it here!

G      -  alphabet
  Foh- - for i in ^:
   oh  -   (o++)+1
     - -  i.pad(" ", ^)
\$\endgroup\$
1
\$\begingroup\$

Pyke, 4 bytes

G\J

G   - alphabet
 \J - "\x0B".join(^)

Joins alphabet by vertical tabs

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

C# 73 68 bytes (Thanks to raznagul)

I'm pretty new to this. Do I need to include class/main declaration overhead for C#?

Edited to include anonymous function declaration

()=>{for(var x='a';x<123;)Console.WriteLine("".PadLeft(x-97)+x++);};
\$\endgroup\$
4
  • \$\begingroup\$ Welcome to PPCG :) For this challenge (and most) you have two options. Either include the boilerplate (main et al) with what you are doing, or... you can create a function, and return either a list of strings for each row, or a string that, if you printed it, would display correctly. \$\endgroup\$
    – Stephen
    Commented Jun 8, 2017 at 20:24
  • \$\begingroup\$ If you use upper case the while condition changes to x<91 saving 1 byte. And you can save another 2 bytes by removing the {} around the WriteLine-statement. \$\endgroup\$
    – raznagul
    Commented Jun 9, 2017 at 9:27
  • \$\begingroup\$ I've found another 3 bytes that can be golfed away: 1) Use var instead of char. 2) In PadLeft write x-97. 3) Use for instead of while declaring x in the loop: for(var x='A';x<97;) \$\endgroup\$
    – raznagul
    Commented Jun 9, 2017 at 9:44
  • \$\begingroup\$ thanks! I always thought I couldn't use var in a lambda. \$\endgroup\$
    – Broom
    Commented Jun 9, 2017 at 13:45
1
\$\begingroup\$

Modern Pascal 2.0, 43 bytes

for var l:=97 to 122 do write(chr(l),#13);

Explanation For loop range is the ascii of 'a' to 'z', and the output is converting the ordinal to character, followed by LF (Line Feed, not CRLF), thus producing a forward diagonal alphabet. Also, Modern Pascal does not require the Begin/End block on simple instructions like this.

// Author of Modern Pascal

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