28
\$\begingroup\$

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.
\$\endgroup\$
  • 2
    \$\begingroup\$ A single trailing newline is acceptable, but no other formatting changes are allowed. So a trailing space on each line would not be permitted? \$\endgroup\$ – James Oct 25 '19 at 18:04
  • 2
    \$\begingroup\$ @DJMcMayhem Correct - no trailing spaces. Darn that rules out [char][space] times length, doesn't it? ;-) \$\endgroup\$ – AdmBorkBork Oct 25 '19 at 18:05
  • \$\begingroup\$ Can we return a list of strings? \$\endgroup\$ – Nick Kennedy Oct 25 '19 at 18:41
  • 2
    \$\begingroup\$ @NickKennedy Yes, that's fine. \$\endgroup\$ – AdmBorkBork Oct 25 '19 at 18:47
  • 1
    \$\begingroup\$ I like the 3d bump effect around the J. \$\endgroup\$ – Eric Duminil Oct 27 '19 at 13:22

51 Answers 51

8
\$\begingroup\$

Haskell, 53 bytes

[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!

| improve this answer | |
\$\endgroup\$
7
\$\begingroup\$

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

| improve this answer | |
\$\endgroup\$
6
\$\begingroup\$

Charcoal, 7 9 bytes

UT↙Eα…α⊕κ

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

  α     Uppercase alphabet
 E      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 UT simply suppresses Charcoal's default rectangular output, apparently needed for this question for some reason.

| improve this answer | |
\$\endgroup\$
5
\$\begingroup\$

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
i read in class
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 think im reading,really im no smart reader
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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Woah neat language! \$\endgroup\$ – mackycheese21 Oct 26 '19 at 4:41
  • \$\begingroup\$ I like how typos of missing spaces are intentional \$\endgroup\$ – mackycheese21 Oct 26 '19 at 4:42
  • \$\begingroup\$ 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 ;) ). \$\endgroup\$ – JosiahRyanW Oct 26 '19 at 6:53
  • \$\begingroup\$ Did you make this language to have a valid reason to say the word "brainfuck" in class? \$\endgroup\$ – anatolyg May 18 at 23:56
5
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ -1: echo {Z..A}|sed ':l;/[B-Z]/p;s///;tl'|tac \$\endgroup\$ – jnfnt Oct 29 '19 at 22:41
  • \$\begingroup\$ @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? \$\endgroup\$ – Digital Trauma Oct 29 '19 at 23:07
  • \$\begingroup\$ 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") \$\endgroup\$ – jnfnt Nov 4 '19 at 22:48
4
\$\begingroup\$

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

J, 34 bytes

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

Try it online!

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
3
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Wolfram Language (Mathematica), 76 bytes

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

enter image description here

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – LegionMammal978 Oct 26 '19 at 16:12
2
\$\begingroup\$

Ruby, 57 bytes

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

Try it online!

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

Japt -R, 14 bytes

;Båi ®¬¸Ãû
mx1

Saved a byte thanks to @Shaggy.

Gained 4 bytes due to fixing a bug.

Test it

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ rPS can be ¬¸. \$\endgroup\$ – Shaggy Oct 26 '19 at 9:23
  • \$\begingroup\$ @dzaima Fixed now \$\endgroup\$ – Embodiment of Ignorance Oct 26 '19 at 15:45
2
\$\begingroup\$

K (oK), 34 33 bytes

-1 byte thanks to ngn

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

Try it online!

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

Canvas, 13 bytes

Z[± *ZL³- ××]

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

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ This outputs with parens and quotes. I don't think that's allowed. \$\endgroup\$ – pppery Oct 26 '19 at 18:15
  • \$\begingroup\$ @pppery "You can print it to STDOUT or return it as a function result." \$\endgroup\$ – ngn Oct 26 '19 at 18:23
  • 2
    \$\begingroup\$ What dialect of K would you suggest for learning the language? \$\endgroup\$ – Jonah Oct 27 '19 at 19:34
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – ngn Oct 28 '19 at 14:21
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – ngn Oct 28 '19 at 14:25
2
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ As outputting a list of lines is acceptable, you can remove the Y \$\endgroup\$ – caird coinheringaahing Oct 27 '19 at 3:34
  • \$\begingroup\$ @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. \$\endgroup\$ – Nick Kennedy Oct 27 '19 at 7:29
  • \$\begingroup\$ 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. \$\endgroup\$ – caird coinheringaahing Oct 27 '19 at 7:38
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Nick Kennedy Oct 27 '19 at 9:45
2
\$\begingroup\$

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

Try it online.

Another 75 bytes:

for i in range(27):print(' '.join(chr(64+i-x)for x in range(i)).center(51))

Try it online.

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ You can remove the space in chr(65+x) for x in .... \$\endgroup\$ – pppery Oct 27 '19 at 13:23
  • \$\begingroup\$ @pppery it have been fixed. tnx. \$\endgroup\$ – Hamidreza Oct 27 '19 at 14:29
2
\$\begingroup\$

PowerShell, 37 bytes

25..0|%{' '*$_+[char[]]((90-$_)..65)}

Try it online!

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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
| improve this answer | |
\$\endgroup\$
  • 2
    \$\begingroup\$ Here is an alternative 8 bytes solution. Same idea and same bytecount, but uses fewer commands. \$\endgroup\$ – Wisław Nov 6 '19 at 15:14
2
\$\begingroup\$

Forth (gforth), 62 bytes

: f 25 for i spaces 25 i - for i 65 + emit ."  "next cr next ;

Try it online!

Code explanation

: f            \ start a new word definition
  25 for       \ loop from 25 to 0
    i spaces   \ print loop-index spaces
    25 i - for \ loop from (25 - loop-index) to 0
      i 65 +   \ add inner loop-index to 65 (ascii 'A')
      emit     \ output ascii char for value
      ."  "    \ output a single space
    next       \ end inner loop
    cr         \ output a newline
  next         \ end outer loop
;              \ end word definition
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

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"
..
| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Retina, 35 bytes


25* 

.
Y`.`RL
L^$w`^(..)*
$#1* $'

Try it online! Explanation:


25* 

Insert 25 spaces.


.

Insert .s in all available positions. This results in 26 .s, because both the start and end can have a . inserted.

Y`.`RL

Cyclically transliterate the .s using a reversed uppercase alphabet.

L^$w`^(..)*

List all (necessarily overlapping) prefixes of even numbers of characters, in reverse order (i.e. longest prefix to shortest).

$#1* $'

For each prefix, output the number of pairs as a run of spaces (effectively deleting the letters) plus its suffix.

| improve this answer | |
\$\endgroup\$
2
\$\begingroup\$

Java (JDK), 82 bytes

v->{var x="";for(char c=64;++c<91;)System.out.printf("%"+(c-38)+"s%n",x=c+" "+x);}

Try it online!

Credits

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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

| improve this answer | |
\$\endgroup\$
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – caird coinheringaahing Oct 25 '19 at 18:49
  • \$\begingroup\$ @cairdcoinheringaahing Thank you! Nice tips ;) and you just saved me one byte! \$\endgroup\$ – game0ver Oct 25 '19 at 18:53
  • 1
    \$\begingroup\$ Your output has trailing spaces from the centering, which this challenge does not allow. \$\endgroup\$ – xnor Oct 25 '19 at 22:13
  • \$\begingroup\$ @xnor Nice catch! Fixed it! \$\endgroup\$ – game0ver Oct 25 '19 at 22:34
1
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Red, 76 bytes

a:""repeat n 26[insert a rejoin[sp#"@"+ n]print next pad/left copy a n + 26]

Try it online!

| improve this answer | |
\$\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.