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

2
\$\begingroup\$

C (gcc), 37 bytes

f(i){for(i=2912;i++%113;printf(&i));}

Inspired by @NieDzejkob; needs to be run on a little endian ASCII machine from a terminal supporting vertical tabs. 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\$
  • 1
    \$\begingroup\$ You can save some bytes with backticks and a literal newline for your join: jsfiddle.net/pL1onLqb \$\endgroup\$ – Stephen Jun 8 '17 at 2:21
  • \$\begingroup\$ Save a byte using some ES8: ''.padEnd(i)+n \$\endgroup\$ – Shaggy Jun 8 '17 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 '17 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\$
  • \$\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 Jun 8 '17 at 14:38
  • \$\begingroup\$ I didn't notice it... thanks for -8bytes \$\endgroup\$ – J42161217 Jun 8 '17 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\$

AWK, 40 bytes

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

Try it online!

I'm curious if there's a shorter way to do this in AWK.

\$\endgroup\$
  • \$\begingroup\$ not sure if the rules allow it, but replace BEGIN with END and add 1 char for the needed ctrl-d ? \$\endgroup\$ – Olivier Dulac Jun 9 '17 at 13:38
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\$
  • \$\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 '17 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 '17 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 '17 at 9:44
  • \$\begingroup\$ thanks! I always thought I couldn't use var in a lambda. \$\endgroup\$ – Broom Jun 9 '17 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\$
  • 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 '17 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 '17 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 '17 at 12:13
1
\$\begingroup\$

tcl, 54 47

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

demo

\$\endgroup\$
  • \$\begingroup\$ @avl42: mine is longer than yours :P \$\endgroup\$ – sergiol Jun 12 '17 at 17:09
  • \$\begingroup\$ @avl42: Mine is NOW shorter than yours, using your own poison! \$\endgroup\$ – sergiol Jun 13 '17 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\$
1
\$\begingroup\$

Noether, 52 bytes

"abcdefghijklmnopqrstuvwyxz"~aL(" "i*Pai/P"
"Pi1+~i)

Try it here!

Pushes the alphabet and loops through it, increasing the number of spaces before the character by one each time.


A non competing solution for 26 24 bytes is:

26(" "i*P0Ai/P"
"Pi1+~i)

Try it here!

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

Swift 3, 75 bytes

for i in 0..<26{print(String(repeating:" ",count:i)+String(i+10,radix:36))}
\$\endgroup\$
1
\$\begingroup\$

Groovy, 40 38 bytes

i=0;("a".."z").each{println" "*++i+it}

Previous solution:

0.upto(25){println" "*it+("a".."z")[it]}

iis used to store the number of spaces that must be printed before each letter. The program iterates through the range "a".."z" (the alphabet), printing each letter with i spaces before it and increments i inline.

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

Common Lisp, SBCL, 70 bytes

(dotimes(i 26)(format t"~v@t~a
"i(aref"abcdefghijklmnopqrstuvwxyz"i)))

Looping through letters of alphabet and outputting accurate number of spaces before each letter.

another 70 bytes solution:

(format t"~{~26<~a~#@t~>
~}"(coerce"abcdefghijklmnopqrstuvwxyz"'list))

looping through letters and justifying to 26 columns, where word to justify is letter+accurate number of spaces.

building alphabet list using code-char would make it 76 bytes:

(format t"~{~26<~a~#@t~>
~}"(loop as i from 97 to 122 collect(code-char i)))
\$\endgroup\$
1
\$\begingroup\$

dc, 53 52 bytes

0si[32Plj1+dsjli>S]sS[0sjlid0<S1+dsi64+dPAP90>M]dsMx

Try it online!

Uppercase because checking that we're below character 90 (Z) is one fewer byte than checking that we're below character 122 (z). Otherwise pretty straightforward: one macro to print spaces and another to call the spacing macro, print the letter, and print a newline.

-1 byte because I forgot to golf my 10 into an A.

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

Pyth, 9 bytes

m+*;xGddG

Try it online!

The other Pyth approach is golfier because it uses enumerated map, which is 1 byte shorter. I just wanted to post a solution with regular map m, that happens to use the same variable, d as the built-in space. That may be inconvenient, because you cannot refer to the space with d. However, I did a work-around with ;, which gets the global value of the innermost lambda variable.

This returns a list of lines. In order to join them by newlines, we just need to add j in front of the whole code (the link contains the j for readability).

Explanation

jm+*;xGddG  - Full program.

 m       G  - Map over the alphabet with a variable d.
  +         - Add:
   *          - The multiplication of:
     xGd        - The index of the current letter in the alphabet (0-indexed) and
    ;           - Space (which is the global value of d, the innermost lambda 
variable).
        d     - The current letter.
j           - Optional: Join by newlines.
\$\endgroup\$
1
\$\begingroup\$

QBasic, 54 bytes

SCREEN 12
FOR x=1TO 26
LOCATE x,x
?CHR$(x+96)
NEXT

Explanation

SCREEN 12       Set the screen mode to something that can actially handle > 20 chars on a line
FOR x=1TO 26    Loop from 1 to 26
LOCATE x,x      Set the cursior to the screen position x,x, starting at 1,1 on the top left.
?CHR$(x+96)  Print the current letter of the alphabet
NEXT
\$\endgroup\$
1
\$\begingroup\$

C#, 82 bytes

var b="";for(int i=0;i<=25;i++){var a=(char)(97+i);b+=new string(' ',i)+a+"\r\n";}

Try it online!

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

C++ (gcc), 73 bytes

As unnamed generic lambda, requires a stream as parameter (like std::cout)

[](auto&O){for(char c=96;++c<123;O<<c<<'\n')for(char w=c-96;--w;O<<' ');}

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.