# Backwards Alphabet Triangle

Without taking any input, output this exact text:

                         A
B A
C B A
D C B A
E D C B A
F E D C B A
G F E D C B A
H G F E D C B A
I H G F E D C B A
J I H G F E D C B A
K J I H G F E D C B A
L K J I H G F E D C B A
M L K J I H G F E D C B A
N M L K J I H G F E D C B A
O N M L K J I H G F E D C B A
P O N M L K J I H G F E D C B A
Q P O N M L K J I H G F E D C B A
R Q P O N M L K J I H G F E D C B A
S R Q P O N M L K J I H G F E D C B A
T S R Q P O N M L K J I H G F E D C B A
U T S R Q P O N M L K J I H G F E D C B A
V U T S R Q P O N M L K J I H G F E D C B A
W V U T S R Q P O N M L K J I H G F E D C B A
X W V U T S R Q P O N M L K J I H G F E D C B A
Y X W V U T S R Q P O N M L K J I H G F E D C B A
Z Y X W V U T S R Q P O N M L K J I H G F E D C B A


## Rules

• Output can be given by any convenient method.
• You can print it to STDOUT or return it as a function result.
• Either a full program or a function are acceptable.
• A single trailing newline is acceptable, but no other formatting changes are allowed.
• Capital letters are required.
• Standard loopholes are forbidden.
• This is so all usual golfing rules apply, and the shortest code (in bytes) wins.
• A single trailing newline is acceptable, but no other formatting changes are allowed. So a trailing space on each line would not be permitted? – James Oct 25 '19 at 18:04
• @DJMcMayhem Correct - no trailing spaces. Darn that rules out [char][space] times length, doesn't it? ;-) – AdmBorkBork Oct 25 '19 at 18:05
• Can we return a list of strings? – Nick Kennedy Oct 25 '19 at 18:41
• @NickKennedy Yes, that's fine. – AdmBorkBork Oct 25 '19 at 18:47
• I like the 3d bump effect around the J. – Eric Duminil Oct 27 '19 at 13:22

[tail$do c<-reverse a;' ':[c|c<=d]|d<-a] a=['A'..'Z']  Try it online! This uses that each line has exactly 25 spaces. So, instead of separately handling the prefix spaces and the spaces between letters, we take 26 spaces, and decide whether to put a letter after each. This unfortunately gives one extra leading space, which we remove. 54 bytes foldl(\m c->map(' ':)m++[c:' ':last m])["A"]['B'..'Z']  Try it online! 55 bytes "A"%['B'..'['] s%(h:t)=((' '<$t)++s):(h:' ':s)%t
s%_=[]


Try it online!

# C (gcc),  82 79 77 75  74 bytes

Saved 2 bytes thanks to @ceilingcat
Saved 1 byte thanks to @gastropner

Derived from my 2nd JS answer.

f(x,y,s){for(x=0,y=25;~y;putchar(s>51?x=!y--,13:s&x>y?90-s/2:32))s=++x+y;}


Try it online!

### How?

We start with $$\x=0\$$ and $$\y=25\$$. We increment $$\x\$$ at the beginning of the line. We set $$\x\$$ to $$\0\$$ and decrement $$\y\$$ at the end of the line, which is reached when $$\x+y=52\$$. We stop when $$\y=-1\$$.

This gives:

   0        1         2         3
123456789012345678901234567890...
25 .........................A
24 ........................B.A
23 .......................C.B.A
22 ......................D.C.B.A
21 .....................E.D.C.B.A
⋮


We append a letter when $$\x+y\$$ is odd and $$\x\$$ is greater than $$\y\$$, or a space otherwise.

The ASCII code of the letter at $$\(x,y)\$$ is given by:

$$90-\left\lfloor\frac{x+y}{2}\right\rfloor, (x+y)\equiv 1 \pmod 2$$

# Charcoal, 7 9 bytes

ＵＴ↙Ｅα…α⊕κ


Try it online! Link is to verbose version of code. Explanation:

  α     Uppercase alphabet
Ｅ      Map over characters
α   Uppercase alphabet
…    Truncated to length
κ Current index
⊕  Incremented
↙       Output with a 135° rotation


Effectively, this starts with the A in the bottom right corner, then works its way to the top left printing longer and longer prefixes of the uppercase alphabet each time, each prefix being printed towards the bottom left. The ＵＴ simply suppresses Charcoal's default rectangular output, apparently needed for this question for some reason.

# V (vim), 16, 15, 12 bytes

¬ZAòé hòòxâÄ


Try it online!

Hexdump:

00000000: ac5a 41f2 e920 68f2 f278 e2c4            .ZA.. h..x..


Thanks to Kritixi Lithos for helping me golf a few off.

Explanation:

¬ZA                 " Insert every character between 'Z' and 'A'
" The cursor is on the 'A'
ò         ò      " Recursively...
é<space>        "   Insert a space
h       "   Move back one character
"   If we're on the first column, this will break the loop
ò     " Recursively...
x    "   Delete the current character
â   "   Stop looping if there's only one non-whitespace character on this line
Ä  "   Duplicate this line upward

• Hint for 14b: you can do better than Ó – user41805 Oct 25 '19 at 18:46
• @KritixiLithos I'll see your 14, and raise you 12 :) – James Oct 25 '19 at 19:07
• Nice, didn't know about â (looks like there are a few other similar ones in normal_keys.vim) – user41805 Oct 25 '19 at 19:18
• Does this count as 12 bytes though? 12 characters, yes. Same goes for the answer of Neil: codegolf.stackexchange.com/a/194860/90048 – D. Kovács Oct 28 '19 at 17:56
• @D.Kovács Yes, it is exactly 12 bytes. See the hexdump I provided – James Oct 28 '19 at 19:01

# Poetic, 686 bytes

the a-b-c corner
i was a child of ten or eleven
i said i am smart,i am likely to get an answer
i got a chance to read papers,novels or some old poetry
as i read,i paused a bit
the words,i do admit,were a huge issue
please tutor,i said,i desire a nap
i truly do not
i fibbed
i am hiding a r-real g-great l-lie,a secret
i am idiot,i cant t-truly r-r-read
i need a lesson,i say,i really do
not a whole lot of people are helping teach me
i want a tutor,i say,i really want someone smart
i call a skilled tutor on my phone
as i call a person,i see a letter key,then i press down
it worked!i see a letter shape
amazing start for me


Try it online!

Poetic is an esolang I made in 2018 for a class project. It's basically brainfuck with word-lengths instead of symbols.

• Woah neat language! – mackycheese21 Oct 26 '19 at 4:41
• I like how typos of missing spaces are intentional – mackycheese21 Oct 26 '19 at 4:42
• The spaces are missing only because I'm golfing this language. Usually, programmers of Poetic are encouraged to use spacing and punctuation freely (and use words more than 10 letters long for those pesky runs of small numbers ;) ). – JosiahRyanW Oct 26 '19 at 6:53

# J, 34 bytes

((32#~26-#)<@u:@,32,@,.65+|.)\i.26


Try it online!

# Bash + common GNU tools, 42

echo {Z..A}|sed -n ':l;p;s/[B-Z]//;tl'|tac


### Explanation

• echo {Z..A} is a bash brace expansion that outputs Z Y X W V U T S R Q P O N M L K J I H G F E D C B A
• The sed expression is a loop that:
• :l Define a label l
• print the current pattern space
• s/[B-Z]// match the first instance of B-Z and replace it with ""
• tl if a match occurred above, jump back to label l
• (implicit) otherwise quit. -n suppresses implicit output of the pattern space at the end of line processing.
• The output of the sed is the required triangle, but upside down. The tac reverses it line-by-line to give the required output.

Try it online!

• -1: echo {Z..A}|sed ':l;/[B-Z]/p;s///;tl'|tac – jnfnt Oct 29 '19 at 22:41
• @jnfnt Thanks. I see that it does work, but so far I haven't been able to figure out how. In particular the s/// appears to be deleting the first B-Z letter in the pattern space - but how does that work? – Digital Trauma Oct 29 '19 at 23:07
• If the pattern between the first two slashes after "s" is empty, sed will assume you want to use the previous regular expression that was used. (From gnu.org/software/sed/manual/html_node/Addresses.html: "The empty regular expression ‘//’ repeats the last regular expression match") – jnfnt Nov 4 '19 at 22:48

# Python 2, 53 bytes

i=26
s='A'
while i:i-=1;print' '*i+s;s='%c '%(91-i)+s


Try it online!

We take care not to introduce any trailing spaces, which means avoiding center and also avoiding adding a space with A for the first row.

# R, 78 72 63 bytes

for(i in 1:26){cat(strrep(" ",26-i));cat(LETTERS[i:1],fill=52)}


Try it online!

Nothing fancy. First print spaces, then print letters.

Improvement inspired by https://codegolf.stackexchange.com/a/195078/89953, but cannot comment there because of reputation.

# Wolfram Language (Mathematica), 76 bytes

Array[StringRiffle[Reverse@ToUpperCase@Alphabet[][[;;#]]]&,26]~Column~Center


• I don't think this answer meets the specifications of the challenge as written, since the correct output includes literal rows of spaces. The shortest compliant version I can come up with is 83 bytes (including a golf of the row generation): StringRiffle[PadLeft[Capitalize@Alphabet[][[#;;1;;-1]]&~Array~26]/. 0->"","~"," "]&, replacing the ~ with a literal newline. Note that the space in /. 0 is necessary. – LegionMammal978 Oct 26 '19 at 16:12

# Ruby, 57 bytes

puts (?A..?Z).map{|c|' '*(90-c.ord)+[*?A..c].reverse*' '}


Try it online!

• You can save one byte by moving puts inside (?A..?Z).map{|c|puts' '*(90-c.ord)+[*?A..c].reverse*' '} – Vasu Adari Oct 28 '19 at 6:36

# Japt-R, 14 bytes

;Båi ®¬¸Ãû
mx1


Saved a byte thanks to @Shaggy.

Gained 4 bytes due to fixing a bug.

Test it

• rPS can be ¬¸. – Shaggy Oct 26 '19 at 9:23
• @dzaima Fixed now – Embodiment of Ignorance Oct 26 '19 at 15:45

# K (oK), 34 33 bytes

-1 byte thanks to ngn

(-26-!26)$c${,/32,'|65+!x}'1+!26


Try it online!

• c$' -> c$ – ngn Oct 26 '19 at 15:41
• @ngn Thank you! I should have tried it myself :) – Galen Ivanov Oct 26 '19 at 15:55
• ah, i missed this submission. mine is an awful lot like this but in k4 ... – scrawl Nov 4 '19 at 15:56
• @scrawl Your solution is much shorter them mine :) – Galen Ivanov Nov 4 '19 at 19:30

# Canvas, 13 bytes

Ｚ［± ＊ＺＬ³－ ××］


Try it here!

Explanation:

Z[± *ZL³- ××]
Z[          ] map over the prefixes of the uppercase alphabet
±             reverse the current prefix
*           interleave it with spaces
ZL³-       substract the loop index from 26
×     that many spaces
×    prepend the spaces to the prefix


7 bytes with padding with spaces. yep, 2x bytecount to "remove" them..

# K (ngn/k), 27 bytes

1_|^\(," "/+,a),a:c$90-!26  Try it online! !26 is 0 1..25 90-!26 is 90 89..65 c$ convert to chars: "ZY..A"

a: assign to a

(,..), prepend as a single element

• +,a flip enlist, i.e. make each char a length-1 string: (,"Z";,"Y";..;,"A")

• " "/ join with spaces (in some dialects of k this may be " "/:)

^\ without-scan, i.e. start with "Z Y..A", then remove "Z", then remove "Y", etc, and collect intermediate results

| reverse

1_ drop the first, as it's an all-spaces string

• This outputs with parens and quotes. I don't think that's allowed. – pppery Oct 26 '19 at 18:15
• @pppery "You can print it to STDOUT or return it as a function result." – ngn Oct 26 '19 at 18:23
• What dialect of K would you suggest for learning the language? – Jonah Oct 27 '19 at 19:34
• @Jonah my favourite is k5/k6 (these were very similar, so i consider them a single dialect), which is what oK and ngn/k follow. oK has a nice manual and interactive examples. unfortunately the real k5 and k6 never saw the light of day. – ngn Oct 28 '19 at 14:21
• @Jonah if you intend to get a job - k4 is still widely used in the form of kdb+ and q, so it might be worth learning. there are some learning materials about it at kx systems' website. 32-bit k4 is free for non-commercial use. kona follows the older k3. the newest "shakti", also known as k7, is still being designed; it might change significantly before it's released. it's followed by ktye/i. – ngn Oct 28 '19 at 14:25

# Jelly, 13 bytes

ØALḶ⁶ẋṚżUK$ƤY  Try it online! A full program that prints the desired output to STDOUT. ## Explanation ØA | Uppercase letters L | Length (26) Ḷ | Lowered range (0..25) ⁶ẋ | Space that many times (vectorises) Ṛ | Reverse list ż | Zip with:$Ƥ  | - Following applied to each prefix of the uppercase letters:
U     |   - Reverse
K    |   - Join with spaces
Y | Join with newlines


Without the final Y, a list of lists of Jelly strings woulf be returned, with the spaces and letters in separate sublists. As such, I’ve gone with joining the outer list with newlines and relying on Jelly’s default printing method to produce the correct output.

• As outputting a list of lines is acceptable, you can remove the Y – caird coinheringaahing Oct 27 '19 at 3:34
• @cairdcoinheringaahing The issue is that the output would be a list of lists of strings because of the ż, and it’s only by virtue of Jelly’s outputting to STDOUT that it looks ok. – Nick Kennedy Oct 27 '19 at 7:29
• As strings are the same as char arrays (which are generated by your program) in Jelly, I'd argue that the output constitutes a list of lines. However, it's entirely up to you whether to accept that argument or not. – caird coinheringaahing Oct 27 '19 at 7:38
• @cairdcoinheringaahing The issue is it doesn’t return a list of character arrays, but a list of lists of two character arrays each - the spaces and letters are in separate sub lists. I’ve previously been told by more experienced golfers that such a return type wouldn’t be permitted, and so I’ve gone with the output to STDOUT. Replacing ż with ;" would resolve the issue, but I’d then still be at 13 bytes without the Y. – Nick Kennedy Oct 27 '19 at 9:45

# 05AB1E, 8 bytes

ASuηí».c


Try it online!

A           # push the alphabet, "abcdefghijklmnopqrstuvwxyz"
S          # split to a list of chars
u         # uppercase
η        # prefixes
í       # reverse each
»      # join by newlines, joining sublists by spaces
.c    # center

• Here is an alternative 8 bytes solution. Same idea and same bytecount, but uses fewer commands. – Wisław Nov 6 '19 at 15:14

# k4, 24 bytes

(-26-!26)$|:',\.Q.A,'" "  explanation:  .Q.A,'" " /append space to each capital letter ("A ";"B "; "C "; ... ) ,\ /join scan, join each element successively and return intermediate results ("A ";"A B ";"A B C "; ... ) |:' /reverse each (-26-!26)$               /left-pad each with -26 -27 -28 ...


run like:

q)k)(-26-!26)$|:',\.Q.A,'" " " A" " B A" " C B A" " D C B A" ..  # Pyth, 20 bytes VlGp*dt-lGNjdr_<GhN1  Pretty happy with this, since it's my first Pyth answer. Probably can be golfed a lot # Explanation VlG for N in range(26) p*dt-lGN 26-N spaces outputted <GhN First N alphabet characters _ Reversed r Capitalised j 1 Joined with spaces (space after each character)  Try it online! # JavaScript (Node.js), 65 bytes f=(n=27,s=A )=>n>52?'':s.padStart(n)+f(++n,Buffer([38+n,32])+s)  Try it online! # JavaScript (Node.js), 79 bytes More maths, more bytes. f=(x=y=0)=>y<26?Buffer([x<y+26?y+x++&x>25-y?156-x+y>>1:32:(x=!++y,13)])+f(x):''  Try it online! # Retina 0.8.2, 57 bytes  ZYXWVUTSRQPONMLKJIHGFEDCBA .$.$*$&$'¶ \B\w$&
O
G.


Try it online! Explanation:


ZYXWVUTSRQPONMLKJIHGFEDCBA


Insert the reversed alphabet.

.
$.$* $&$'¶


Turn it into a triangle.

\B\w
$&  Space out the letters. O  Get the lines in the correct order. G.  Remove an extraneous trailing newline. (Retina 0.8.2 always adds a trailing newline, so there would have been two; if I had used Retina 1 then I could have claimed that newline as my allowed newline.) # Python3, 91 bytes for _ in range(26):print(f'{" ".join([*map(chr,range(65,91))][0:_+1][::-1]):^52}'.rstrip())  Try it online! -1 byte thanks to @cairdcoinheringaahing • Welcome to the site! Just as a start, there are a few quick golfs that you can do, such as removing the space after the colon. I'd recommend linking to an online testing environment, such as Try it online!, so that others can verify and help you golf your solution – caird coinheringaahing Oct 25 '19 at 18:49 • @cairdcoinheringaahing Thank you! Nice tips ;) and you just saved me one byte! – game0ver Oct 25 '19 at 18:53 • Your output has trailing spaces from the centering, which this challenge does not allow. – xnor Oct 25 '19 at 22:13 • @xnor Nice catch! Fixed it! – game0ver Oct 25 '19 at 22:34 # Icon, 84 bytes procedure main() s:="";i:=1to 26&s[1:1]:=" "||char(64+i)&write(right(s,25+i))&\z end  Try it online! ## Python 3, 78 bytes for i in range(26):print(' '*(25-i)+' '.join(chr(65+i-j) for j in range(i+1)))  A straightforward solution. # Red, 76 bytes a:""repeat n 26[insert a rejoin[sp#"@"+ n]print next pad/left copy a n + 26]  Try it online! # Python 3, 76 75 bytes: -1 byte thanks to @pppery for i in range(27):print((27-i)*' '+' '.join(chr(64+i-x)for x in range(i)))  Another 75 bytes: for i in range(27):print(' '.join(chr(64+i-x)for x in range(i)).center(51))  • You can remove the space in chr(65+x) for x in .... – pppery Oct 27 '19 at 13:23 • @pppery it have been fixed. tnx. – Hamidreza Oct 27 '19 at 14:29 # Perl 6, 33 bytes {(' 'Xx(25...0))Z~[\R,] 'A'..'Z'}  Try it online! Anonymous code block that returns a list of lines. ### Explanation: { } # Anonymous code block ' 'Xx # String multiply spaces (25...0) # by the range 25 to 0 ( )Z~ # Zip these indents with [\ ] # The triangular reduced R, # Reversed list concatenation 'A'..'Z' # Of the alphabet  # PowerShell, 37 bytes 25..0|%{' '*$_+[char[]]((90-$_)..65)}  Try it online! # C# (Visual C# Interactive Compiler), 81 bytes var x="A";for(char y='\x41';++y<92;x=y+" "+x){WriteLine(new string(' ',91-y)+x);}  Try it online! # Keg323130262524 25 bytes (SBCS) A(\≤|:Z$- ⅍*,:Aɧ∑, ,)⑨
,)


Try it online!

Hey, Keg's coming 9th (at the time of writing)! Contains unprintable characters. Uses the 26 byte approach but uses a space converted to a string to pad lines.

### 25 bytes

A(|:Aɧ ⅍!3--*,∑, ,)1+
,


Try it online!

### 26 bytes (SBCS)

A(|:Aɧ(!;;-| ,)∑, ,)1+
,


-4 bytes by using stack mechanics rather than the register

Explained

A(␚|:Aɧ(␚!;;-| ,)∑, ,)1+¶,
A                           #Push "A" onto the stack
(␚|                         #26 times:
:Aɧ                     #   Push a generated range from A to the top of stack
(␚!;;-| ,)              #   Space-align the row
∑, ,)                   #   Print each character space seperated
1+                      #   Increment the top letter by one
¶,                      #   Print a newline


Substitute ␚ for the actual unprintable control key and ¶ for a literal newline

### 30 bytes (SBCS)

A&(|A&:&ɧ(!;-| ,)(, ,)&1+&
,


Explained

A&(␚|A&:&ɧ(␚!;-| ,)(, ,)&1+&¶,
A&                              #Put A in the register
(␚|                           #26 times:
A&:&ɧ                     #   Push a generated range from A to the top of stack
(␚!;-| ,)            #   Space-align the row
(, ,)       #   Print each character space seperated
&1+&   #   Increment the top letter by one
¶, #   Print a newline


Substitute ␚ for the actual unprintable control key and ¶ for a literal newline

### 31 bytes (SBCS)

A&(\≤|A&:&ɧ(\≤!-| ,)(, ,)&1+&
,


Explained

A&(\≤|A&:&ɧ(\≤!-| ,)(, ,)&1+&¶,)
A&                              #Store A in the register
(\≤|                          #26 times:
A&:&ɧ                     #   Push a generated range from A to the top
(\≤!-| ,)            #   Align it using spaces
(, ,)       #   Print the row
&1+&   #   Increment the letter
¶,)#   Print a newline (replace ¶ w/ \n)
`