# Diagonal Alphabet

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!

• 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? Jun 8 '17 at 23:30
• @DigitalTrauma as long as it appears the same, I don't care what kind of whitespace you use. Jun 8 '17 at 23:31
• Can I use tabs instead of spaces?
– user69335
Jun 9 '17 at 23:28
• @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. Jun 9 '17 at 23:32
• does not affecting appearance include having an extra leading space or 2? Sep 11 '17 at 17:08

# QBIC, 27 bytes

[26|?space$(a-1)+chr$(a+96)


## Explanation

[26|          FOR a = 1 to 26
?space$(a-1) PRINT a-1 spaces (SPACES$ is a QBasic function that prints x spaces)
+chr$(a+96) and a char representation of a+96  # Tcl, 52 bytes set i 96;time {puts [format %[incr j]c [incr i]]} 26  time is really a tool for measuring time spent, but it's also handy for repetition of code. Indentation and letter are advanced in each iteration. Ascii code i needs preset to one-before-first-letter, j will be auto-set to 1 on first incr. If run in an interactive tclsh, the time would also output timings, but if the line is in a script, then it's silent, except for the diagonal. ## ZX Spectrum BASIC, 29 bytes FOR i=NOT PI TO VAL "25": LPRINT TAB i;CHR$ (i+VAL "97"): NEXT i


Numeric literals carry a 6-byte penalty, so using VAL saves me 3 bytes (VAL is a 1-byte token). Note: The ZX Spectrum's output area is only 22 lines high, so I'm sending the output to the printer instead.

# T-SQL, 63 bytes

DECLARE @ INT=0a:PRINT SPACE(@)+CHAR(@+65)SET @+=1IF @<26GOTO a


Written more conventionally, that would be:

DECLARE @ INT=0
a:
PRINT SPACE(@) + CHAR(@+65)
SET @ += 1
IF @<26 GOTO a


Tested and working on SQL Server 2012.

# Japt, 10 9 bytes

Saved 1 byte thanks to @Shaggy

;C£RiXiYî


Run it online!

## Explanation:

;C£RiXiYî
;C          // Lowercase alphabet
£         // Map; At each char:
R        //   Newline
iX      //   Insert: X (Iterative char)
iYî   //   Insert: " " repeated Y (index) times


By default, i inserts the target char at index 0. So, RiXiYî becomes Yî +X+R.

• ;C£RiXiYî for 9 bytes. Jun 8 '17 at 6:52
• ;C¬£XiYç with -R also works for 9. Jun 8 '17 at 7:11
• A short cut for mÈ would allow for an 8 byte solution ;) Jun 8 '17 at 13:58

# Nano, 186 77 bytes

M- represents the alt key

M-ia
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

I've seen a few Vim answers on this site so I thought I would do a nano answer. Its not nearly as terse as the Vim answers but its still better than typing out the whole thing.

This is pretty simple (a lot simpler than my original answer). M-i sets the auto-indent on. This means that every line will copy the indentation of the last. So we start with a and every line add a space and a letter all the way through.

## Mathematica, 39 Bytes

Grid@DiagonalMatrix@Alphabet[]/. 0->" "


This has trailing whitespace.

Explanation:

                    Alphabet[]          - Create a list of the alphabet
DiagonalMatrix@                    - Use that as the diagonal of a matrix
/. 0->" " - Replaces the 0's with whitespace
Grid@                                   - Then turn it into a 2D grid

• Since a list of strings is allowed, and you are not asked to print it or anything, I don't think you need the Grid@. Aug 19 '17 at 16:13

# braingasm, 20 bytes

26[#[32.]97+#+.10.>]


26 times, print (.) a space (32) # (current position on the tape) times; increase cell (+) by 97, then by #; and print the current cell value, along with a newline (10); then go to next cell (>).

# 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.

• not sure if the rules allow it, but replace BEGIN with END and add 1 char for the needed ctrl-d ? Jun 9 '17 at 13:38

# Perl 6, 25 bytes

{" " «x«^26 Z~'a'..'z'}


This function returns a list of the required strings: "a", " b", " c", ...

^26 is a list of the numbers from 0 to 25. «x« is the string-replication hyperoperator that maps each element n of its right-hand side to the left-hand side replicated n times, producing the list "", " ", " ", .... That list is then zipped with string concatenation (the Z~ operator) with the range of letters from 'a' to 'z'.

# Scala, 41 bytes

('a'to'z').map(a=>println(" "*(a-'a')+a))


(0 to 25).map(a=>printf("%s%c\n"," "*a,97+a))


It is 1 byte shorter than

(0 to 25).map(a=>println(" "*a+(97+a).toChar))


Try it online!

• Here is a 37 bytes solution: 'a'to'z'map(c=>println(" "*(c-97)+c)) Nov 4 '18 at 14:29

# JAVASCRIPT

Option 1: 59 bytes

a='';for(i=0;i<26;)a+=''.padEnd(i++)+(i+9).toString(36)+



Option 2: 60 bytes

a='';for(i=0;i<26;)a+=' '.repeat(i++)+(i+9).toString(36)+



Option 3: 61 bytes

a='',i=0;while(i<26)a+=' '.repeat(i++)+(i+9).toString(36)+



Option 4: 67 bytes

a='';for(i=0;i<26;)a+=' '.repeat(i++)+String.fromCharCode(96+i)+



Option 5: 68 bytes

[...Array(26)].map(_=>' '.repeat(++i-10)+i.toString(36),i=9).join


• easily tested in the browser's console :) Jun 8 '17 at 20:00

# Bash, 3836 35 bytes

printf "%*s
" echo $[++i]\ {a..z}  Try it online! 2 bytes less thanks to @DigitalTrauma 1 byte less thanks to @NahuelFouilleul "%*s\n" takes padding as an argument. $((++i))\ {a..z} for each letter increment and prepend i plus space (arithmetic expansion)

• Replace $(( )) with $[ ]. Jun 8 '17 at 15:04
• If another user suggests an edit that improves your score and you use it, it is usual to credit that user in your answer - Thanks! Jun 11 '17 at 18:30
• I don't know if newline is counted as two characters or one, in that case \n can be replaced with new line Jun 12 '17 at 13:15

# R, 56 bytes

for(i in 1:26){cat(rep(" ",i-1),LETTERS[i],'\n',sep='')}


Try it online!

Prints i-1 spaces and the ith letter of the alphabet, plus a newline, 26 times.

Outgolfed by Giuseppe (47 bytes), user2390246 (40 bytes), and Sven Hohenstein (37 bytes), but this is the only answer (so far) that doesn't use diag.

# Pyth, 9 8 bytes

.e+*dkbG


Try it online

### Explanation

.e     G  For each element of 'abc...z'...
*dk    Take a string of spaces with length equal to the index...

• 0 indexing really helps for this, doesn't it? Jun 8 '17 at 2:02
• I'm two months late, but you can take out the j because outputting as a list is allowed. Jul 25 '17 at 8:28
• @clap Improvements are always welcome.
– user48543
Jul 25 '17 at 13:02

## Julia, 42 bytes

for i=0:25 println(" "^i,Char[97+i][1])end


Pretty straight forward, print space and character.

Try it online!

# Ruby, 18 bytes

puts [*?a..?z]*?\v


Does not work on TIO, link for reference:

Try it online!

# Pyth, 11 bytes

j.b+*dNY26G


Explanation:

Try it online!

j.b+*dNY26G   expects no input

j             joins on new line
.b           for...in loop, uses two iterator variables
+          joins *dN and Y
*dN       repeats d (space) N times, where N is one of .b's iterating variables
Y      another one of .b's iterating variables
26    the array being iterated for N,.b automatically takes the unary range
G   initialized to the lowercase alphabet, the array being iterated for Y


# SOGL V0.12, 2 bytes

z╝


Try it Here!

z   push the alphabet
╝  convert to a diagonal array
implicitly output as a newline joined string


# TI-Basic, 71 69 bytes

"
For(I,1,26
Disp sub(Ans+Ans+Ans+Ans,1,I)+sub("ABCDEFGHIJKLMNOPQRSTUVWXYZ",I,1
End

• Don't know how I missed that, thanks for -26 bytes @StephenS Jun 8 '17 at 15:50
• I think you can just do sub(Ans+Ans+Ans+Ans,1,I). Aug 25 '17 at 0:43
• @lirtosiast Thanks, I should have noticed that one. Aug 25 '17 at 2:19

# Pyth, 13 bytes

I've noticed that I've been getting better at these, but Dave or Mr. Xcoder will school me any day of the week.

Update: Pyth tester is down, rip back up.

#p*dt=hZhG=tG


Explanation:

#         Loop until error
p*dt=hZ  Print without newline: " " times ++Z - 1 (Z defaults to 0) (Could have used + instead of p, but it's easier to explain)
hG       Implicit print with newline: The first character of the alphabet
=tG      Remove the first letter in the alphabet variable


Try it online!

1+:0\:'+\' \k:>:#,_$:'␚-!k@a,  Where ␚ is a literal substitute character Every line has 3 leading spaces Try it online! # uBASIC, 36 bytes Anonymous function that takes no input and outputs to the console. 0ForI=0To25:?Tab(I);Chr$(65+I):NextI


Try it online!

• Soon: 100% of alphabet challenge are necromancer'd to the top being called "basic" xD. Jan 31 '18 at 18:31
• @MagicOctopusUrn OH NO!!! You discovered my plot!! Jan 31 '18 at 18:36
• Creating meta-thread to vote on replacing tag "alphabet" with "basic" lmao! Seriously, I love these challenges, but there isn't an alphabet challenge not completed in 05AB1E... ;_; Jan 31 '18 at 18:46

# PowerShell, 35 bytes

$i=97;0..25|%{" "*$_+[char]$i;$i++}


Try it online!

Pipes an array of 0 through 25 to ForEach-Object, which cycles through ascii codes and prefixes with a space multiplied by an incrementing variable.

• Roll the [char] calculation into the loop variable for 29 bytes -- Try it online! Mar 19 '18 at 13:25

# Mouse-2002, 43 bytes

(A.Z1+<^A.B:(B.^" "B.1-B:)A.97+!'"!"A.1+A:)


Needs to be run in the Mouse-2002 Interpreter REPL. Working interpreter can be found here.

# Python 3, 51 bytes

print("\n".join(" "*n+chr(n+97)for n in range(26)))

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

## Canvas, 2 bytes

ｚ＼


Try it here!

# 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


# J, 19 16 bytes

u:32+(*=)65+i.26


Try it online!

# 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:

-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
`