72
\$\begingroup\$

Inspired by a bug in a solution to this challenge, your challenge is to produce this exact text:

                         ZYXWVUTSRQPONMLKJIHGFEDCBA
                        YXWVUTSRQPONMLKJIHGFEDCBA
                       XWVUTSRQPONMLKJIHGFEDCBA
                      WVUTSRQPONMLKJIHGFEDCBA
                     VUTSRQPONMLKJIHGFEDCBA
                    UTSRQPONMLKJIHGFEDCBA
                   TSRQPONMLKJIHGFEDCBA
                  SRQPONMLKJIHGFEDCBA
                 RQPONMLKJIHGFEDCBA
                QPONMLKJIHGFEDCBA
               PONMLKJIHGFEDCBA
              ONMLKJIHGFEDCBA
             NMLKJIHGFEDCBA
            MLKJIHGFEDCBA
           LKJIHGFEDCBA
          KJIHGFEDCBA
         JIHGFEDCBA
        IHGFEDCBA
       HGFEDCBA
      GFEDCBA
     FEDCBA
    EDCBA
   DCBA
  CBA
 BA
A
  • The first line will have 25 spaces, then the alphabet backwards starting from the 26th letter (ZYXWVUTSRQPONMLKJIHGFEDCBA), then a newline.
  • The second line will have 24 spaces, then the alphabet backwards starting from the 25th letter (YXWVUTSRQPONMLKJIHGFEDCBA), then a newline.
  • ...
  • The last (26th) line will have no spaces, then the alphabet backwards starting from the 1st letter (A), then a newline.

Additional rules:

  • Your program may use any allowed output methods.
  • One trailing newline and/or one leading newline is allowed.
  • There must be one newline between lines containing the letters, no more.
  • The letters must be all uppercase.

As with , the shortest submission wins. Good luck!

Leaderboard:

var QUESTION_ID=141725,OVERRIDE_USER=61563;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

\$\endgroup\$
7
  • 4
    \$\begingroup\$ To me it looks like the light cast by the bat-signal \$\endgroup\$
    – scottinet
    Sep 5 '17 at 19:47
  • 4
    \$\begingroup\$ Closely Related. \$\endgroup\$
    – Mr. Xcoder
    Sep 5 '17 at 20:26
  • \$\begingroup\$ Can each line have an extra space in front of it? \$\endgroup\$
    – hyper-neutrino
    Sep 5 '17 at 20:35
  • 3
    \$\begingroup\$ Could each line have trailing spaces after the last letter? \$\endgroup\$
    – miles
    Sep 5 '17 at 20:49
  • 1
    \$\begingroup\$ @miles yes, that's fine. \$\endgroup\$
    – MD XF
    Sep 5 '17 at 21:34

115 Answers 115

1 2 3
4
1
\$\begingroup\$

Emojicode, 156 bytes

🏁🍇🍦a🔤                         ZYXWVUTSRQPONMLKJIHGFEDCBA🔤🍮i 0🔁◀i 26🍇😀🍪🔪a i➖25 i🔪a➕i 25🐔a🍪🍮i➕i 1🍉🍉

Try it online!

Explanation:

🏁🍇     👴 start program
🍦a🔤                         ZYXWVUTSRQPONMLKJIHGFEDCBA🔤     👴 big ol string
🍮i 0           👴 declare loop variable
    🔁◀i 26🍇      👴 loop 26 times
        😀🍪         👴 print concatenated string 
        🔪a i➖25 i     👴 number of spaces
        🔪a➕i 25🐔a🍪     👴 reverse alphabet minus last letter
        🍮i➕i 1       👴 increment loop variable
    🍉              👴 end loop
🍉                 👴 end program
\$\endgroup\$
1
\$\begingroup\$

SmileBASIC 3, 67 64 bytes

-3 bytes from @12Me21 using the -I trick

Unfortunately the console is one character too narrow to fit the first line without wrapping the last character. Oh well.

FOR I=-25TO.?" "*-I+RIGHT$(@ZYXWVUTSRQPONMLKJIHGFEDCBA,-I+1)NEXT
\$\endgroup\$
1
  • \$\begingroup\$ There's a neat trick you can do to avoid STEP -1. Make the loop go from -25 to 0, and use -I instead of I. \$\endgroup\$
    – 12Me21
    Apr 25 '18 at 12:37
1
\$\begingroup\$

Swift, 118 bytes

var s="";for i in 0..<26{for _ in 0..<25-i{s+=" "};for j in 0..<26-i{s+="\(UnicodeScalar(90-i-j)!)"};s+="\n"};print(s)

Prettyfied:

var s = ""

for i in 0 ..< 26 {
    for _ in 0 ..< 25 - i {
        s += " "
    }

    for j in 0 ..< 26 - i {
        s += "\(UnicodeScalar(90 - i - j)!)"
    }
   
    s += "\n"
}  

print(s)

Try it online!

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

Stax, 13 9 bytes

á*↔?[O╒v4

Run and debug it at staxlang.xyz!

Unpacked (15 bytes) and explanation

VAr|]mc%Hv)
VAr                Uppercase alphabet, reversed
   |]              List of suffixes
     m             Map rest of program over array, printing each element with a linefeed:
      c              Copy top of stack
       %             Length
        Hv           Double and decrement
          )          Pad string on left with spaces to the specified length

I think that VAr|]mc%Hv|z SHOULD work for 10 bytes (once packed), but what looks to me like a bug kills that solution. I stupidly confused |z with ) there. Thanks @recursive for pointing that out (and saving even another byte)!

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

T-SQL, 115 bytes

DECLARE @ VARCHAR(51)=SPACE(25)+'ZYXWVUTSRQPONMLKJIHGFEDCBA'a:PRINT @
SET @=STUFF(@,len(@)/2,2,'')IF len(@)>0GOTO a

Shorter to just hard-code the initial string, then I used STUFF() to snip out two characters from the middle each loop.

I can save 3 bytes by using a CHAR(51) instead of a VARCHAR(51), but that prints full-width trailing spaces for all rows, which don't appear to be allowed.

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

C# (.NET Core), 133 114 bytes

var S="";for(int I=26;I-->0;){var C='@';for(;C++<I+64;)S+=" ";for(;C>'@';)S+=C--;S+="\n";}System.Console.Write(S);

Try it online!

var S="";                   // Initialize the return string
for(int I=26;I-->0;){       // For all 26 rows (with I as the space count)
    var C='@';              // Initializing C with the char '@' which is one under 'A'
    for(;C++<I+64;)         // For all spaces needed and sets the char one up ('@' -> 'A', 'A' -> 'B')
        S+=" ";             // Add a space to the string
    for(;C>'@';)            // For all characters which are needed from the char countet above up down to 'A'
        S+=C;               // Add the char to the string
    S+="\n";                // Add a new line to the string
}
System.Console.Write(S);    // Output the string
\$\endgroup\$
1
\$\begingroup\$

K4, 22 bytes

Solution:

,/'(1_')\0 25_|51$.Q.A

Explanation:

Generate two lists and reduce each until they are empty.

,/'(1_')\0 25_|51$.Q.A / the solution
                  .Q.A / A..Z
               51$     / pad to 51 chars
              |        / reverse it
         0 25_         / cut (_) at indices 0 and 25
   (   )\              / perform this along
    1_'                / drop (_) first from each (') list
,/'                    / flatten (,/) each (')

Bonus:

Another 22 byte solution:

,/'(1_')\(25#$`;|.Q.A)
\$\endgroup\$
1
\$\begingroup\$

><>, 51 49 bytes

2d*:&:1(?v:"@"+$1-48*}40.
l2(?vob1.>r~
-20.>~ao&1

Try it online!

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

Dyalog APL, 34 23 21 bytesSBCS

↑{(1-2×⍵)↑⌽⍵↑⎕A}¨⌽⍳26

Try it online!

Thanks to Adám for the help!

Explanation:

↑{(1-2×⍵)↑⌽⍵↑⎕A}¨⌽⍳26
                  ⍳26 ⍝ 1..26
                 ⌽    ⍝ Reverse, 26..1
 {             }¨     ⍝ For each in this range. Iteration: ⍵
            ↑         ⍝ Take...
           ⍵          ⍝ ...⍵ elements...
             ⎕A       ⍝ ...from the alphabet
          ⌽           ⍝ Reverse
         ↑            ⍝ Pad with spaces...
  (1-2×⍵)             ⍝ ...(1 - 2*current iteration) elements
↑                     ⍝ Format
\$\endgroup\$
4
  • \$\begingroup\$ You have a stray . \$\endgroup\$
    – Adám
    Sep 7 '17 at 12:18
  • \$\begingroup\$ Also, I'd write instead of . \$\endgroup\$
    – Adám
    Sep 7 '17 at 12:19
  • \$\begingroup\$ Save two bytes: ↑{(1-2×⍵)↑⌽⍵↑⎕A}¨⌽⍳26 \$\endgroup\$
    – Adám
    Sep 7 '17 at 12:25
  • \$\begingroup\$ That's clever :). Ty. \$\endgroup\$
    – Ven
    Sep 7 '17 at 12:32
1
\$\begingroup\$

Gaia, 14 bytes

26…v§&¦₵Av┅+†ṣ

Try it online!

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

Ruby, 58 bytes

Not the best answer for Ruby, but still good enough to get second place out of three entries lol. I just wanted to try a regex-based solution.

s=' '*26+[*?A..?[].reverse*''
puts s while s.sub!(/ \S/){}

Try it online!

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

Whitespace, 163 bytes

Try it online!

                                    (s = space, t = tab, l = linefeed)
sssttstsl   push 26                 For x = 26 times

lssl        start: ""
sls         dup (Stack: [26, 26])       For y = x times

lsssl       spaces:
ssstl       push 1
tsst        sub                             decrement space counter
sls         dup
ltstl       jz end_spaces                   if space counter > 0
ssstsssssl  push 32
tlss        outchar                             print space
lslsl       jmp spaces
lsstl       end_spaces:                 next y

sll         drop                        drop y
sls         dup (Stack: [26, 26])

lssssl      letters:
sls         dup                         for y = x to 0
ssstssssssl push "@"
tsss        add (Stack: [26, 26, "Z"])      add y to "@" to get start letter
tlss        outchar                         print that letter
ssstl       push 1
tsst        sub                             decrement y
sls         dup
ltsstl      jz end_letters
lslssl      jmp letters                 next y
lssstl      end_letters:

sll         drop                        drop y
ssstl       push 1
tsst        sub                         decrement x
sls         dup
ltsttl      jz end
ssststsl    push 10
tlss        outchar                     print newline
lsll        jmp start               next x
\$\endgroup\$
1
\$\begingroup\$

Japt -R, 15 12 11 bytes

;Båi ËiEçÃÔ

Test it

;Båi ËiEçÃÔ
;B              :Uppercase alphabet
  å             :Cumulatively reduce by
   i            :  Prepending
     Ë          :Map each element a 0-based index E
      i         :  Prepend
       Eç       :  Space repeated E times
         Ã      :End map
          Ô     :Reverse
                :Implicit output joined with newlines
\$\endgroup\$
1
\$\begingroup\$

Pip -l, 18 bytes

R R*AZ@,\,26.sX,26

Run it here! Alternately, here's the equivalent 19-byte solution in an older version of Pip: Try it online!

Explanation

               ,26  Range(26)
             sX      String-multiply each element by space: list of 0 to 25 spaces
        \,26        Inclusive-range(1,26)
       ,             Range(each element)
      @              Use each range as an index into...
    AZ               Uppercase alphabet
            .       Concatenate those two lists itemwise
  R*                Reverse each string in the resulting list
R                   Reverse the list itself
                    Autoprint the list, one string per line (-l flag)

Another 18-byte answer using map:

RAZ@,1+_.sX_M R,26

Try it online! (19-byte equivalent)

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

Lua, 82 bytes

s=' 'for i=90,65,-1 do o=s:rep(i-65)for j=i,65,-1 do o=o..s.char(j)end print(o)end

Try it online!

Human readable code:

s=' '
for i=90,65,-1 do
  o=s:rep(i-65)
  for j=i,65,-1 do
    o=o..s.char(j)
  end
  print(o)
end
\$\endgroup\$
1
\$\begingroup\$

BRASCA, 23 bytes

e[{:[Eo{]x:}[{:D+o]lox]

Try it online!

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

Zsh, 41 bytes

eval 1={A..Z}'$1;<<<${(l:#1-65:)}$1;'|tac

Try it online!

Explanation:

  • 1={A..Z}'$1;<<<${(l:#1-65:)}$1;': construct the string 1=A$1;<<<${(l:#1-65:)}$1; 1=B...1; 1=C...1; ... 1=Z...1; (with every letter from A to Z in place of the {A..Z} in each case)
  • evaluate that string as zsh code:
    • 1=A$1: prepend A (or which ever letter is in that repetition) to the variable $1
    • ${(l:#1-65:)}: generate #1-65 spaces:
      • #1: Take the ASCII character code of the first character of $1
      • subtract 65. The first iteration will have A as the first character of $1, the character code of which is 65, and since 65-65=0, no spaces will be printed. Then for further letters, another space will be added each time.
    • $1: and append the variable $1
    • <<<: and print that with a newline
  • |tac and reverse the output line-wise

Zsh, 36 bytes

eval 2={A..Z}'$2;<<<$1$2;1+=\ ;'|tac

Try it online!

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

Elixir, 84 bytes

import Enum
map 25..0,&(IO.puts List.duplicate(' ',&1)++reverse(slice ?A..?Z,0..&1))

Try it online!

Still want to find a way around that List.duplicate call....

\$\endgroup\$
0
\$\begingroup\$

Forth (gforth), 54 bytes

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

Try it online!

How it works

: f ( n -- ) \ Print n+1 lines of searchlight.
  for        \ loop from n to 0 inclusive [i]
    i spaces   \ print i spaces
    i for      \ loop from i to 0 inclusive [j];
               \ in Forth, the innermost loop count is always i
      i 65 + emit \ print a char whose charcode is j + 65
    next       \ end inner loop
    cr         \ print a newline
  next ;     \ end outer loop
25 f       \ push 25 and call f

Just started fiddling with Forth. Unlike the golfing tip says, it looks like n for .. next loop is the shortest for simple decreasing loops and n1 n0 do .. loop for increasing loops. The recursive call word recurse or recursive is way too verbose, and it still costs at least an if .. then.

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 16 bytes

₂F₂N-D<ð×?Aus£R,

Try it online!

₂F                # for N in [0, 1, 2, ..., 25]:
  ₂N-D<ð×?        # print 25 - N spaces with no trailing newline
          Aus£R,  # print the first 26 - N letters of the uppercase alphabet, reversed
                  # (implicit) exit for loop
\$\endgroup\$
0
\$\begingroup\$

Pyth, 21 bytes

=_r1GV26
+*\ -25NG=tG

Try it online!

Basically, it sets G to ZYXWVUTSRQPONMLKJIHGFEDCBA, and next prints space repeated some amount of times and G, then removes the first letter of G.

\$\endgroup\$
0
\$\begingroup\$

Rockstar, 101 bytes

X's26
while X
O's""
let Y be X
while Y
cast Y+64 into L
let O be+L
let Y be-1

let X be-1
say " "*X+O

Try it here (Code will need to be pasted in)

\$\endgroup\$
0
\$\begingroup\$

Excel, 66 bytes

=LET(r,26-ROW(1:26),x,CONCAT(CHAR(65+r)),REPT(" ",r)&RIGHT(x,r+1))

Link to Spreadsheet

\$\endgroup\$
0
\$\begingroup\$

Splinter, 253 bytes

Z{\A\
}H{\C\BZ}A{\M\L\K\JG{\I\HD}D{\G\F\E\DH}D}E{\V\U\TB{\S\R\Q\PF{\O\NA}F}B}S{\ }T{SS}U{TT}V{UU}W{VV}WVS\Z\Y\X\WEWV\Y\X\WESTUW\X\WETUW\WESUWEUW\U\TBSTW\TBTWBSW\R\Q\PFW\Q\PFSTUV\PFTUVFSUV\NAUVASTV\L\K\JGTV\K\JGSV\JGVGSTU\HDTUDSU\F\E\DHU\E\DHST\DHTHS\BZZ

Try it online!

Link is to a Python interpreter.

\$\endgroup\$
0
+100
\$\begingroup\$

Vyxal, 704 24 bytes

Try it online!

₄ʀƛ:ʁṘƛ65+C;ṅ$ð*$+;Ṙ

Behind door number 3, we have this answer - again just prints out the string (Edit 1: never mind, it doesn't)

\$\endgroup\$
5
  • \$\begingroup\$ 23 bytes \$\endgroup\$
    – emanresu A
    May 10 at 11:26
  • \$\begingroup\$ outgolfed \$\endgroup\$
    – lyxal
    May 10 at 11:35
  • \$\begingroup\$ rip - might as well put the 23 byter \$\endgroup\$ May 10 at 11:39
  • \$\begingroup\$ @Ausername the 23 byter prints everything in reverse. \$\endgroup\$ May 10 at 11:51
  • \$\begingroup\$ Try it Online! For 20 \$\endgroup\$
    – lyxal
    May 10 at 12:48
1 2 3
4

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.