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

163 Answers 163

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

C++ (gcc), 50 48 bytes

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

Try it online!

\$\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
    Sep 29, 2020 at 16:02
2
\$\begingroup\$

i386 Bootsector, 19 bytes (Technically 512 due to padding)

Here is a hexdump of the program without padding:

0000-0010:  b4 0e b3 61-88 d8 cd 10-b0 0a cd 10-fe c3 80 fb  ...a.... ........
0000-0013:  7b 75 f1                                         {u.

And here is the original assembly:

mov ah, 0x0e
mov bl, 'a'
l:
    mov al, bl
    int 0x10
    mov al, 0xa
    int 0x10
    inc bl
    cmp bl, '{'
    jne l

Very simple. Diagonal works by printing a newline without a carriage return.

\$\endgroup\$
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
    Dec 9, 2021 at 15:05
  • \$\begingroup\$ @pxeger Fixed.. \$\endgroup\$
    – Bgil Midol
    Dec 9, 2021 at 15:07
  • \$\begingroup\$ Actually, I was wrong; leading spaces are allowed. But it's still shorter this way. \$\endgroup\$
    – pxeger
    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\$
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
    Jun 8, 2017 at 2:21
  • \$\begingroup\$ Save a byte using some ES8: ''.padEnd(i)+n \$\endgroup\$
    – Shaggy
    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
    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\$
    – DELETE_ME
    Jun 8, 2017 at 14:38
  • \$\begingroup\$ I didn't notice it... thanks for -8bytes \$\endgroup\$
    – ZaMoC
    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
    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
    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
    Jun 9, 2017 at 9:44
  • \$\begingroup\$ thanks! I always thought I couldn't use var in a lambda. \$\endgroup\$
    – Broom
    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\$
1
\$\begingroup\$

Batch, 187 114 bytes

@set s=
@for %%p in (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)do @call:e %%p
:e
@echo(%s%%1
@set s= %s%
\$\endgroup\$
3
  • 1
    \$\begingroup\$ You don't need the @s inside the ()s. Also, you don't need c at all - you can just add a space to s each time. By avoiding setlocal enabledelayedexpansion I got this down to 112 bytes. \$\endgroup\$
    – Neil
    Jun 12, 2017 at 15:33
  • \$\begingroup\$ I've successfully removed the @s, variable c, and now I couldn't figure out how to echo the variable s without delayedexpansion. \$\endgroup\$
    – stevefestl
    Jun 13, 2017 at 8:15
  • 1
    \$\begingroup\$ Since you're so close already, here's my 112-byte solution: @set s=&for %%p in (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)do @call echo %%s%%%%p&call set s= %%s%%. \$\endgroup\$
    – Neil
    Jun 13, 2017 at 12:13
1
\$\begingroup\$

tcl, 54 47

time {puts [format %[incr i]c [expr $i+96]]} 26

demo

\$\endgroup\$
2
  • \$\begingroup\$ @avl42: mine is longer than yours :P \$\endgroup\$
    – sergiol
    Jun 12, 2017 at 17:09
  • \$\begingroup\$ @avl42: Mine is NOW shorter than yours, using your own poison! \$\endgroup\$
    – sergiol
    Jun 13, 2017 at 23:04
1
\$\begingroup\$

vim 14+16=30 keystrokes

16 keystrokes if you have alpha in nrformats already (I mean, who hasn't?), 30 otherwise.

:set nf=alpha<cr>
ia<esc>
qqYp<c-a>I <esc>q
24@q

Angle brackets denote single characters, e.g. <c-a> is ctrl+a (increment). Actual newlines only for clarity. Seriously, set nf+=alpha is really neat, and it's a feature I've missed in a few specific cases when programming.

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

Rexx (Regina), 41 37 bytes

do i=1 to 26
  say right(d2c(96+i),i)
end

Try it online!

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

SimpleTemplate, 66 42 bytes

This simply loops through all characters and outputs them one by one, with newlines and spaces.

{@forfrom"a"to"z"}{@echolV,_}{@setV V," "}

This abuses the automatic variable _ and the automatic flattening of echoed arrays and automatic newline with echol.

Ungolfed: (produces invalid results due to whitespace)

{@for chr from "a" to "z"}
    {@echo indentation, chr, "\n"}
    {@// will create an array like: [[[..., " "], " "], " "]}
    {@set indentation indentation, " "}
{@/}{@// automatically added after the code}


Old version:

There's a repeat function, but I couldn't use it because it's broken.
But this works too.

{@for_ from"a"to"z"}{@incz}{@callstr_repeat intos" ",z}{@echols,_}

Ungolfed: (produces incorrect results due to whitespace added)

{@set z 0}{@//removes warning}
{@for chr from "A" to "Z"}
    {@inc spaces by 1}
    {@call str_repeat into indentation " ", spaces}
    {@echo indentation, chr, "\n"}
{@/}{@// automatically added after the code}
\$\endgroup\$
1
\$\begingroup\$

Retina, 93 bytes


aAbBc¶3d¶4e¶5f¶6g¶7h¶8i¶9jA0kA1lA2mA3nA4oA5pA6qA7rA8sA9tB0uB1vB2wB3xB4yB5z
B
¶2
A
¶1
\d+
$* 

Try it online!

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