# Make an alphabet searchlight!

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.

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

• To me it looks like the light cast by the bat-signal Commented Sep 5, 2017 at 19:47
• Commented Sep 5, 2017 at 20:26
• Can each line have an extra space in front of it? Commented Sep 5, 2017 at 20:35
• Could each line have trailing spaces after the last letter? Commented Sep 5, 2017 at 20:49
• @miles yes, that's fine. Commented Sep 5, 2017 at 21:34

# QBIC, 48 bytes

[26|Q=Q+chr$(a+64)][26,1,-1|?space$(b)+_s_fQ|,-b

## Explanation

[26|            FOR a = 1; a <= 26; a++
Q=Q+chr$(a+64) Add to Q$ a chr() being a+64 (A-Z in succession)
]               NEXT (at the end of the loop, Q$is ABC...XYZ) [26,1,-1| FOR b = 26; b >= 1; b-- ?space$(b)      PRINT b spaces,
+_s             and a substring of
_fQ|         Q$reversed, ,-b taking b characters from the right # VB, 167 bytes i = 26 For a = i To 1 Step -1 For j = a To 1 Step -1 c = c + " " b = b + Chr(64 + j) Next d = d & c & b & vbNewLine c = "" b = "" Next msgbox d first time to participate but i'm not competing to everyone, just myself. lol • Welcome to PPCG! I am not sure about VB, but can you remove the whitespace, like b=b+Chr(64+j)? That would save quite a bit here. – JAD Commented Sep 6, 2017 at 8:11 • @JarkoDubbeldam VB automatically adds spaces when programming in an IDE. I don't think they're required, though. I've seen confusion before about whether to remove them or ignore them. Commented Sep 6, 2017 at 14:13 • @mbomb007 hmm, can you run VB from a file without opening it in an IDE? – JAD Commented Sep 6, 2017 at 14:20 • @JarkoDubbeldam When I deal with Basic's auto-indentation, I usually open a separate text editor, remove as much whitespace as possible, then paste that into the IDE. If auto-format still works and the code runs as expected, I post the code from the text editor. Commented Sep 6, 2017 at 14:40 • Welcome to PPCG :) Following on from the other suggestions, there's plenty that can be golfed out of this. Here's a quick pass I took over it for 103 bytes: for a=26to 1step-1:c="":b="":for j=a to 1step-1:c=c+" ":b=b+chr(64+j):next:d=d&c&b&vbcrlf:next:msgbox d Commented Sep 6, 2017 at 16:47 # DUP, 48 bytes 25 65[^[$][32,1-]#%^^+[^^\-][$,1-]#,10,^][\1-\]# Online DUP interpreter # Octave, 38 bytes (or 46 bytes in tio) flip([spdiags(hankel(90:-1:65)) '']')' Generates the correct output at least on windows installation of Octave, but in tio to be correctly shown the character 0 should be replace by space: [max(32,flip(spdiags(hankel(90:-1:65))')') ''] Try it online! # Perl 6, 57 bytes .put for (' 'Xx(25...0))Z~(('Z'...'A') »...»'A')».join Try it online! ## Expanded: .put # print with trailing newline for # for each of the following ( ' ' Xx # cross using string repetition operator ( 25 ... 0 ) # from 25 down to 0 ) Z~ # zip using string concatenation ( ( 'Z' ... 'A' ) # descending sequence of starting values »...» # combine those into sequences each with an end value of 'A' 'A' )».join # combine each of the sub sequences into strings # Clojure v1.8, 93 bytes Converted Renzo's answer to Clojure. (dotimes[i 26](prn(apply str(concat(repeat(- 25 i)" ")(subs"ZYXWVUTSRQPONMLKJIHGFEDCBA"i))))) # Explanation (dotimes [i 26] ...) We will print 26 lines, i is between[0, 26) (subs"ZYXWVUTSRQPONMLKJIHGFEDCBA"i) Take the string starting from position 'i' (repeat(- 25 i)" ") Repeat the whitespaces, we start from 25 because the last line doesn't have whitespaces (prn(apply str(concat(repeat(- 25 i)" ")(subs"ZYXWVUTSRQPONMLKJIHGFEDCBA"i)))) Concatenate the sequence of whitespaces and the string in order to have the desired effect with 'str' next Try it online! # brainfuck, 119 bytes >+++++[<++>>+++++<-]>+>++++[>++++++++<-]>>-[>+<---]>+++++<<<<[-[->+>.<<]>[->>>.->+<<<<]>>>.->[-<+<<<<+>>>>>]<<<<<<<.>>] Try it online! Could be golfable by better initializing the tape - there is a modulo solution that would pop 90,32,26 and 10, that would also probably leave the tape a little less fragmented. Also could combine all three loops unto one, by juggling the index as the difference from the ASCII code 'Z', or something. # Javascript, 82 bytes for(i=26;i;){console.log(" ".repeat(i-1)+"ZYXVUTSRQPONMLKJIHGFEDCBA".slice(-i--))} Try it online! # Twig, 93 bytes Twig is a template language developed to be used in PHP, which is similar to Smarty, Django or Jinja. {%for a in "Z".."A"%}{{("%"~(26-loop.index)~"s%s")|format(f,range(a,"A")|join())}} {%endfor%} This code relies in the fact that the environment option strict_variables defaults to false. Otherwise, it will break. Try it on https://twigfiddle.com/9umogr (check the raw result). If you want to copy-paste the code, make sure that you disable strict_variables, since the website sets that to true. # Bash + coreutils, 64 bytes printf '%s' {Z..A}|sed 'h;s/./ /g;G;s/ \n//;p;:a;s/ \b.//p;ta;Q' • I like this, but it seems to be missing the newline at the end. Commented Sep 8, 2017 at 1:36 • I guess the requirements were a bit unclear. Commented Sep 8, 2017 at 2:04 # C, 82 characters char*a="ZYXWVUTSRQPONMLKJIHGFEDCBA\n",i=54;main(){while(i)printf("%*s",i-=2,a++);} Works for any character coding, by embedding the full alphabet. We print subsequent trailing substrings in a field twice as wide as required, to get the leading spaces. I had hoped to be able to reduce it further with while(printf());, but couldn't arrange for the return value to reach zero at the right point. ## Retina, 38 bytes 25$* Z
{-2=
$' }TL_L.$
;{:G
\w

Try it online!

### Explanation

25$* Z Initialise the working string to 25 spaces and a single Z. {-2=$'
}TL_L.$The usual approach for generating the alphabet: repeatedly duplicate the last letter, then decrement that letter with a transliteration, removing As instead of decrementing them further. That means once we get to A, the second stage will delete the letter which was added by the first stage, so there won't be any net change and the loop stops. That gives us the first line of the output. ;{:G \w Now we really just repeatedly print the current line and the drop a space followed by a letter. The construction is slightly weird due to how loops and printing works in Retina. We need to print before we drop the letter, which requires a separate stage that otherwise doesn't do anything, and we also need to disable the implicit printing at the end of the program. # Husk, 15 bytes mṠ+ȯR' ←Lhṫ…"ZA Try it online! -5 thanks to Zgarb. Still a newb :p # Pyth, 14 bytes -2 from dave and ven thanks guys V_UG+*dNrG1=PG Explanation coming when I figure it out wake up. ## Pyth, 16 bytes V26p*-25Nd>_rG1N Explanation: V26 26 times, could've written lG, but it's the same p*-25Nd Print without newline: 25-index spaces (could've used + instead of p but it's simpler to explain) >_rG1N Implicit print with newline: The last index characters of the reverse uppercase alphabet Try it online! While you're here, here's Artemis's first answer ported into Pyth: ## Pyth, 21 20 bytes (non-competing) J26W=tJ+*dJ>_rG1-25J An explanation for Artemis's answer: J26 Set J to 26 W While... =tJ Decrement J (J-=1) +*dJ J spaces plus... >_rG1-25J The last 25-index characters of the reverse uppercase alphabet I should stop writing these on my phone Try it online! • Similar to this answer, but > doesn't seem like the way to go. How about setting G to tG, as in V_UG+*dNrG1=tG for 14 bytes? – Dave Commented Sep 7, 2017 at 3:13 • @Dave similar to what answer? Commented Sep 7, 2017 at 3:16 • Yours! This being parent lol – Dave Commented Sep 7, 2017 at 3:16 • @Dave I knew I was doing something wrong Commented Sep 7, 2017 at 3:17 • It's too early for this Commented Sep 7, 2017 at 15:11 # Java, 206 bytes public class Main{public static void main(String[]args){int i,j,k,l=90;for(k=26;k>=0;k--){for(i=k-1;i>0;i--){System.out.print(" ");}for(j=l;j>=65;j--){System.out.print((char)j);}l--;System.out.println();}}} Try it online! • I'm new so not familiar how to add a post, hope to help someone.!! :D Commented Sep 8, 2017 at 10:40 • Also, the bytecount must be visible on the header. Commented Sep 8, 2017 at 11:06 • its actually shorter to define an interface than class. also, the args array doesn't have to be called args, can be let's say a as well. Commented Sep 8, 2017 at 15:48 • You can use public class M to save three bytes. And String[]a to save three more. Commented Sep 8, 2017 at 16:16 # Java, 196 134 bytes Yes, this has no chance of winning overall, but it helps to re-familiarize myself with the language. Any improvements are welcome, but know I have not yet had time to read the Tips or Golfing in Java. public class A{public static void main(String[]a){for(int i=0;i<26;i++){for(int j=0;j<25-i;j++)System.out.print(" ");for(char c=(char)(90-i);c>=65;c--)System.out.print(c);System.out.println();}}} Thanks to JollyJoker for suggesting improvements. I won't get a chance to investigate lambdas for this one, but I'll remember it for the future. This is as short as I'll make this one. Eclipse kept complaining when I changed all ints to chars, so I'll look into that some more. String a(){String r="";for(int i=0;i<26;i++){for(int j=0;j<25-i;j++)r+=" ";for(char c=(char)('Z'-i);c>=65;c--)r+=c;r+="\n";}return r;} Try it online! Ungolfed: public class A { public static void main(String[] args) { for (int i = 0; i < 26; i++) { for (int j = 0; j < 25 - i; j++) System.out.print(" "); for (char c = (char)(90 - i); c> = 65; c--) System.out.print(c); System.out.println(); } } } String a() { String r = ""; for (int i = 0; i < 26; i++) { for (int j = 0; j < 25 - i; j++) r += " "; for (char c = (char)('Z'-i); c >= 65; c--) r += c; r+= "\n"; } return r; } • You can give the answer as a method returning a String instead of a full program. Use Java 8 lambdas for the method. Combine nested for loops if you can find a way. The char 32 is space and 10 is newline; concatenate chars like ""+=c to build a String. Commented Sep 7, 2017 at 11:59 • You can use n-> instead of ()-> even if there's no input. Using it to store a char inside the code might be ok. Commented Sep 7, 2017 at 12:34 • Thanks for the tips! I'll edit my answer in a few hours with your improvements. Commented Sep 7, 2017 at 12:46 • You can copy / paste some lambda boilerplate from here Commented Sep 7, 2017 at 12:51 • Avoid cast by using 'Z' instead of 90 and changing everything from int to char Commented Sep 7, 2017 at 13:14 # VBA, 65 Bytes Anonymous VBE immediate window function that takes no input and outputs to the VBE immediate window For i=0To 25:?Spc(25-i);:For j=0To 25-i:?Chr(90-j-i);:Next:?:Next ### Naïve Version, 68 Bytes For i=0To 25:?Spc(25-i)Right("ZYXWVUTSRQPONMLKJIHGFEDCBA",26-i):Next # Python 2, 86 83 bytes for x in range(25,-1,-1):print(" "*x)+"".join([chr(y+65)for y in range(x+1)][::-1]) Thanks to Stephen for the 3 extra bytes. • 3? less bytes by removing extra spaces: for x in range(25,-1,-1):print(" "*x)+"".join([chr(y+65)for y in range(x+1)][::-1]) Commented Sep 6, 2017 at 23:11 # q/kdb+, 32 31 bytes Solution: raze@/:(1_')\[(25#" ";(|).Q.A)] Example: q)raze@/:(1_')\[(25#" ";(|).Q.A)] " 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" "" Explanation: Create two lists, 1 with 25 spaces, 1 with the reversed alphabet, then drop the first item from each list and join together. Use converge \ to terminate when the output matches previous output (hence this results in a trailing empty line): raze each (1_')\[(25#" ";reverse .Q.A)] / ungolfed solution ( ; ) / two item list 25#" " / 25 take " ", whitespace 25 long reverse .Q.A / .Q.A is uppercase alphabet A..Z, reverse reverses, so Z..A ( )\[ ] / converge running left function with right arguments 1_' / 1 drop (_) each (') removes first item from each sublist and returns result (2 lists) raze each / raze reduces a list of lists, so we reduce each sublist of 2 lists to a single list # Acc!!, 113 bytes 26 Count i while i-_ { Count b while b-25+i { Write 32 } Count t while t-_+i { Write 90-t-i } Write 10 } Try it online! # Implicit, 242322 19 bytes À¦\^(-(1ß-);%\1^ß1ö À « push alphabet »; ¦ « swap case »; \ « reverse »; ^ « push length »; ( « do »; - « decrement string length »; (1..) « while top of stack truthy »; ß « print space »; - « decrement string length »; ; « pop string length »; % « print string »; \1 « knock first character off string »; ^ « push length »; ß1 « print newline »; ö « exit without implicit output if top of stack falsy »; « implicit infinite loop »; Try it online! # Kotlin, 87 71 bytes ## Submission {(0..25).map{(it..25).map{print(" ") it}.map{print('Z'-it)} println()}} ## Beautified { // For it from 25 to 0 (0..25).map { // Print that number of spaces // Print the alphabet backwards from that letter (it..25).map { print(" ") it}.map { print('Z' - it) } // Newline println() } } ## Test var f:()->Unit = {(0..25).map{(it..25).map{print(" ") it}.map{print('Z'-it)} println()}} fun main(args: Array<String>) { f() } # uBASIC, 74 bytes That pesky Chr$ function sure does like to add extra spaces

0ForI=0To25:?Tab(25-I);:ForJ=0To25-I:?Left$(Chr$(90-I-J),1);:NextJ:?:NextI

Try it online!

# MY-BASIC, 100 bytes

Anonymous function that takes no input and outputs to the console

For I=0 To 25
For J=I To 25
Print" "
Next
For K=0 To 25-I
Print Left(Chr(90-I-K),1)
Next
Print;
Next

Try it online!

# Yabasic, 79 bytes

For I=0To 25
For J=I To 25
?" ";
Next
For K=0To 25-I
?Chr$(90-I-K); Next ? Next Try it online! # Recursiva, 50 24 23 22 bytes {B26"P+*' '-L(}Z~}_(26 Try it online! # Canvas, 6 bytes Ｚ［↔］Ｒ⇵ Try it here! Explanation (characters have been changed to their ASCII forms to look monospace): Z push the uppercase alphabet [ ] map over prefixes ↔ reverse horizontally R pad each line with the line number spaces ⇵ and reverse the whole thing vertically ## PHP, 113 Bytes Try it online! Code, recursive function function f($s=0){echo ($s<26)?str_pad("",$s)
.implode(array_reverse(range(chr(65), chr(65+$s))))." ".f($s+1):"";}

Explanation

function f($s=0){ echo ($s<26)?           #it stops at the 26 letter
str_pad("", $s) #padding whitespace .implode(array_reverse(range(chr(65), chr(65+$s))))
#implode the range of letters,
#yes, range works with characters too
#reverse the array because it always starts with A
."                      #concatenate a linebreak
".f(\$s+1):"";          #calling for the next letter
}

# Go, 127 Bytes

package main;import."strings";func main(){for i:=26;i>0;i--{print("\n",Repeat(" ",i-1));for j:=i;j>0;j--{print(string(j+64))}}}

This prints with a leading newline.

package main
import . "strings"
func main(){
for i := 26; i > 0; i-- {
print("\n", Repeat(" ", i-1))
for j := i; j > 0; j-- {
print(string(j + 64))
}
}
}

Try it online!

# SNOBOL4 (CSNOBOL4), 82 bytes

U =REVERSE(&UCASE)
O	OUTPUT =DUPL(' ',SIZE(U) - 1) U
U LEN(1) REM . U	:S(O)
END

Try it online!

Finally got around to a SNOBOL answer for this challenge. Always prints with a trailing newline.