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

# 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. – Shaggy Jun 8 '17 at 6:52
• ;C¬£XiYç with -R also works for 9. – Shaggy Jun 8 '17 at 7:11
• A short cut for mÈ would allow for an 8 byte solution ;) – Shaggy 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@. – Mark S. 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 (>).

# 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)) – 6infinity8 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 :) – w3jimmy 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 $[ ]. – Digital Trauma 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! – Digital Trauma 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 – Nahuel Fouilleul 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? – Stephen 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. – clapp 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 – Timtech Jun 8 '17 at 15:50
• I think you can just do sub(Ans+Ans+Ans+Ans,1,I). – lirtosiast Aug 25 '17 at 0:43
• @lirtosiast Thanks, I should have noticed that one. – Timtech 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. – Magic Octopus Urn Jan 31 '18 at 18:31
• @MagicOctopusUrn OH NO!!! You discovered my plot!! – Taylor Scott 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... ;_; – Magic Octopus Urn 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! – AdmBorkBork 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.

# brainfuck, 64 bytes

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


Try it online!

Prints in uppercase with a trailing newline.

Initialises the tape to 2N, and uses the 16(-3) as the newline, the 32 as the space, the 64 as the start of the uppercase alphabet, the 128(+2) as the counter (-5 each loop), and the cell at the end as the space counter.

## 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  # Pepe, 7976 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  # QBasic 1.1, 35 bytes FOR S=0TO 25 ?SPC(S)CHR$(S+97)
NEXT


-8 thanks to DLosc.

# Z80Golf, 19 bytes

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


Try it online!

Disassembly:

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


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


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