| Bytes | Lang | Time | Link |
|---|---|---|---|
| 016 | Husk | 250219T161153Z | Glory2Uk |
| 010 | Vyxal 3 | 240110T190813Z | Larry Ba |
| 009 | Jelly | 170501T105822Z | Erik the |
| 012 | MATL | 180717T072538Z | Sundar R |
| 039 | Julia 1.0 | 210721T113853Z | MarcMush |
| 084 | Julia 0.4 | 160804T003929Z | Mama Fun |
| 107 | Elixir | 210721T112436Z | Dom Hast |
| 008 | Vyxal j | 210720T145108Z | Aaroneou |
| 209 | plain TeX | 210315T124828Z | plante |
| 057 | Zsh | 210315T141553Z | roblogic |
| 070 | Python 2 | 210313T034016Z | dingledo |
| 015 | Pip | 200916T044625Z | Razetime |
| 054 | Perl 5 with M5.010 | 160803T113125Z | Dom Hast |
| 170 | Common Lisp | 190614T183059Z | David Ho |
| 008 | Stax | 190614T172623Z | recursiv |
| 096 | brainfuck | 190614T172304Z | Helena |
| 006 | 05AB1E | 160803T095220Z | Emigna |
| 094 | Pepe | 190614T090529Z | u-ndefin |
| 097 | JavaScript | 180717T203717Z | MattH |
| 079 | brainfuck | 180717T192635Z | Mitch Sc |
| 146 | Small Basic | 180717T165147Z | Taylor R |
| 009 | Japt R | 170814T091809Z | Shaggy |
| 109 | brainfuck | 180716T130736Z | Dorian |
| 119 | brainfuck | 160804T085603Z | DanTheMa |
| 028 | K4 | 180204T225813Z | mkst |
| 006 | Canvas | 180203T194053Z | dzaima |
| 091 | VBA | 170823T125834Z | Taylor R |
| 088 | Kotlin | 160804T100312Z | Aaron |
| 059 | Mathematica | 160803T105616Z | chyanog |
| 012 | Recursiva | 170910T084350Z | 0xffcour |
| 010 | SOGL V0.12 | 170914T181218Z | dzaima |
| 156 | Python | 170910T193650Z | Spiffo |
| 175 | Common Lisp | 170814T090345Z | Renzo |
| 131 | Java | 160804T085428Z | Syamesh |
| 111 | Clojure | 170501T194337Z | NikoNyrh |
| 029 | CJam | 170501T033006Z | Esolangi |
| 078 | PHP | 161026T113818Z | Jör |
| 327 | Racket | 161030T152238Z | rnso |
| 022 | J | 160803T052701Z | miles |
| 120 | Rust | 161027T074050Z | user6126 |
| 089 | JavaScript ES6 | 161025T222106Z | ETHprodu |
| 125 | R | 160803T104221Z | Rudier |
| 190 | Logo | 160803T221113Z | GuitarPi |
| 029 | Brachylog | 160810T123751Z | Leaky Nu |
| 182 | Clojure | 160809T224635Z | Tyrannos |
| nan | Python 3 | 160805T041033Z | Jeffrey0 |
| 059 | R | 160805T165054Z | user5957 |
| 884 | HTML + CSS | 160806T105519Z | manatwor |
| 113 | Javascript ES6 | 160805T183926Z | Pandacod |
| 175 | JavaScript 177 | 160805T173001Z | Richard |
| 147 | C# | 160803T130004Z | TheLetha |
| 081 | JavaScript ES6 | 160805T133029Z | ASCII-on |
| 105 | Javascript ES5 | 160805T131803Z | Bassdrop |
| 069 | R | 160805T114408Z | plannapu |
| 053 | MATLAB | 160805T113925Z | Stewie G |
| 071 | Python | 160803T151231Z | Nonlinea |
| 188 | Guile | 160805T082147Z | HugoNika |
| 080 | PHP | 160804T061750Z | Crypto |
| 074 | Python | 160803T075308Z | xnor |
| 109 | Python | 160804T182128Z | greyShif |
| 095 | R | 160804T174129Z | Sol |
| 094 | VBA | 160803T060954Z | Joffan |
| 1412 | HTML | 160804T154141Z | MonkeyZe |
| 162 | C# | 160804T120709Z | downrep_ |
| nan | Java 156bytes | 160803T193741Z | Linnea G |
| 122 | QBasic | 160803T144147Z | Chris H |
| 092 | Mathematica 98 96 | 160803T082523Z | DavidC |
| 147 | Racket | 160804T103133Z | Steven H |
| 224 | Batch | 160803T080034Z | Neil |
| 093 | C | 160803T122925Z | owacoder |
| 013 | Pyth | 160804T003650Z | isaacg |
| 021 | Convex | 160803T234818Z | GamrCorp |
| 098 | Python 2 | 160803T195526Z | Sherlock |
| 067 | Cheddar | 160803T181513Z | Leaky Nu |
| 136 | Python 2.7 | 160803T192331Z | Koppany |
| 016 | Jelly | 160803T185310Z | miles |
| 142 | Swift 2.2 | 160803T180848Z | Alexande |
| 100 | Python 2 | 160803T164933Z | ospahiu |
| 037 | Vim | 160803T145927Z | lynn |
| 016 | Pyke | 160803T180927Z | Blue |
| 052 | Powershell | 160803T125827Z | Ben Owen |
| 076 | Retina | 160803T153952Z | mbomb007 |
| 135 | Javascriptusing external libraryEnumerable | 160803T053824Z | applejac |
| 137 | C | 160803T093939Z | R. Kap |
| 060 | ><> | 160803T114945Z | Sok |
| 122 | JavaScript ES6 | 160803T110419Z | user8165 |
| 141 | JavaScript ES6 | 160803T102520Z | edc65 |
| 159 | TSQL | 160803T100928Z | t-clause |
| 018 | Dyalog APL | 160803T095330Z | lstefano |
| 080 | bash | 160803T091408Z | izabera |
| 208 | /// | 160803T091749Z | Erik the |
| 027 | Sesos | 160803T080026Z | Dennis |
| 085 | Python 2 | 160803T072918Z | miles |
| 071 | Ruby | 160803T060609Z | Value In |
| 013 | Jelly | 160803T050523Z | Dennis |
| 058 | Haskell | 160803T054654Z | Doorknob |
| 097 | Python 3 | 160803T044223Z | Leaky Nu |
Husk, 16 bytes
S+ot↔mS+o↔hḣ…"AZ
This looks a little bit long, but the algorithm is incidentally the same as in the other answers.
Commented:
…"AZ -- start with the alphabet string "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
ḣ -- make the prefices
m -- for each prefix do the following:
o↔h -- | remove its first letter, reverse
S+ -- | and join with the corresponding prefix
ot↔ -- now, for the whole thing: reverse, remove the last string
S+ -- and join it with itself
MATL, 12 bytes
26Zv"1Y2@Zv)
Pretty straightforward in MATL, thanks to the Zv symmetric range function.
26Zv - Make the symmetric range around 26 i.e. [1:26 25:-1:1]
" - Iterate through that
1Y2 - Push the literal 'A':'Z' on the stack
@ - Push the current loop index on the stack
Zv - Make the symmetric range around the index
) - Index into the alphabets using this symmetric range
Julia 0.4, 84 bytes
!()=(- =join;a=-char(65:90);b=[a[1:x+1]*a[x:~0:1]for x=0:25];vcat(b,b[25:~0:1])-"
")
Elixir, 107 bytes
import Enum
a=reduce ?A..?Z,[],&(&2++[(at(&2,-1)||[])++[&1]])
map a++tl(reverse a),&IO.puts&1++tl reverse&1
Vyxal j, 8 bytes
kA¦ømƛøm
Explanation:
kA # Uppercase ALPHABET
¦ # Prefixes (A, AB, ABC, ...)
øm # Mirror without duplicating middle
ƛ # For each:
øm # Mirror without duplicating middle
(plain) TeX, 209 bytes
\newcount~~65\newcount\j\j64\tt\def\a#1{{\loop\advance\j1\char\j\ifnum\j<#1\repeat\loop\advance\j-1\char\j\ifnum\j>65\repeat}\par}\def\c#1#2#3.{\loop\advance~#11\a~\ifnum~#2#3\repeat}A\par\c{}<90.\c->66.A\bye
Zsh, 100 96 92 80 57 bytes
-23!! thanks to @pxeger
eval Z+={A..Z}';<<<$Z`rev<<<$Z[1,-2]`;'>f
{<f;tac f}|uniq
We build the string $Z by iterating over A..Z, concat $Z with its reverse, and add the resulting string to file f. Then we print f forwards and backwards.
Python 2, 70 bytes
x=25
exec'b=bytearray(range(65,91-abs(x)));print b+b[-2::-1];x-=1;'*51
Perl 5 with -M5.010, 54 bytes
for$@(A..Z){@;=($_.$/,@;);s/$*/$*$@$*/;say;$*=$@}say@;
Saved bytes thanks to @Xcali!
Common Lisp, 170 bytes
(let ((r "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))(loop for i from 1 to 51 do(let ((l (subseq r 0 (- i (* 2 (- i 26) (floor i 26))))))(format t "~a~a~%" l (subseq (reverse l) 1)))))
Run it: TIO here.
Formatted:
(let ((r "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))
(loop for i from 1 to 51
do(let ((l (subseq r 0 (- i (* 2 (- i 26) (floor i 26))))))
(format t "~a~a~%" l (subseq (reverse l) 1)))))
Breakdown:
(let ((r "ABCDEFGHIJKLMNOPQRSTUVWXYZ"))- variable r holds string range of all characters- variable l holds a substring from the r of length based on the line number, where l = r[0:i - (2 * (i - 26) * i % 26)] ... (2 * (i - 26) * i % 26) this part ensures the i to be this sequence 0...26...0
- format prints the l string and its reversed counter part with skipped first letter (to avoid ABBA, ABCCBA , etc.)
Stax, 8 bytes
çtò-+è╥â
Palindromize the palindromizations of the prefixes of the alphabet. Not very interesting program, but the challenge is back on the front page.
brainfuck, 96 bytes
+++++[->+++++>>++>+++++++++++++<<<<]>[->>>[.>]<[->+>+<<]>+>[-<<+>>]<<<[.<]<]>>>[[.>]<[-]<[.<]>>]
; Initialize memory as: 0 (25) 0 "\n" "A" 0
+++++[->+++++>>++>+++++++++++++<<<<]>
[- ; Repeat 25 times
>>>[.>] ; print all the characters on the band
<[->+>+<<]>+>[-<<+>>] ; copy the last character and increment
<<<[.<] ; print all but the last two characters backwards
<]
>>>
[ ; while there is still characters left
[.>] ; print all the characters
<[-] ; remove last character
<[.<] ; print all characters backwards
>>]
05AB1E, 20 13 12 6 bytes
Saved 2 bytes thanks to Adnan.
Saved 6 bytes thanks to Magic Octopus Urn and some new language functionality.
Aη€ûû»
Explanation
Aη # push prefixes of alphabet
€û # palendromize each prefix
û # palendromize the whole list
» # join on newlines
Pepe, 94 bytes
rEeEeEEeEeREeEeeeeeEREEEEEEerEEReeeReeEREEEeEREEEeEREEeeREEEEEreererEEReeeReeEReReREEeEreeReee
JavaScript - 97 bytes
f=(i,l,q,t,r,a="ABCDEFGHIJKLMNOPQRSTUVWXYZ")=>(r="\n"+q+(c=a[i])+l+t)+(i<25?f(i+1,c,q+c,l+t)+r:"")
Which is called as:
f(0,"","","")
Should the function call factor into the byte count?
brainfuck, 79 bytes
+<++<<--------[>+++++>>[+++<+<]>]<+[[>+>+.<<-]>-[<+>>-.<-]>->.>[->]<<<[<<++>]<]
Formatted:
+<++<<
--------[>+++++>>[+++<+<]>]
<+
[
[>+>+.<<-]
>-[<+> >-.<-]
>->.>[->]
<<<[<<++>]
<
]
Small Basic, 146 bytes
A Script that takes no input and outputs to the TextWindow Object
For i=-25To 25
For j=0To-Math.Abs(i)+25
c=Text.GetCharacter(65+j)
s=s+c
t=c+t
EndFor
TextWindow.WriteLine(s+Text.GetSubText(t,2,j))
s="
t="
EndFor
Try it at SmallBasic.com! Requires IE/Silverlight
Japt -R, 14 9 bytes
;Bå+ mê ê
Explanation
;B :Uppercase alphabet
å+ :Cumulatively reduce by addition
m :Map
ê : Mirror
ê :Mirror
:Implicitly join with newlines and output
brainfuck, 109 bytes
+++++[<+++++>-]<+[>>[>[.>]]>++++++++++<<[>>.<]>[<]>--[<++++++++>-]<[+.<]<-]>>,>[.>]++++++++++.[<[.<]>,>[.>]<]
Explanation
+++++[<+++++>-] 26 times
<+[
>>[>[.>]] print every letter up to new char position
>++++++++++<<[>>.<] if any letter exists print lf
>[<]> resync pointer position
--[<++++++++>-] set new char to A minus 1
<[+.<] increment each letter and print it
<- decrement counter
]
>>, delete last letter
>[.>] print rest of middle line
+++++ +++++. print lf
[ while chars exist
<[.<] print all
>, delete last
>[.>]< print second half (including lf)
]
Alternative
If a leading newline would be alowed, this could also be done with 97 bytes.
+++++[<+++++>-]<+[>>[>[.>]]>++++++++++.--[<++++++++>-]<[+.<]<-]>>,>[.>]++++++++++.[<[.<]>,>[.>]<]
Explanation
+++++[<+++++>-] 26 times
<+[
>>[>[.>]] print every letter up to new char position
>++++++++++. print lf
--[<++++++++>-] set new char to A minus 1
<[+.<] increment each letter and print it
<- decrement counter
]
>>, delete last letter
>[.>] print rest of middle line
+++++ +++++. print lf
[ while chars exist
<[.<] print all
>, delete last
>[.>]< print second half (including lf)
]
Both codes need interpreters that use "end of input = 0".
brainfuck, 1733 121 119 bytes
----[---->+<]>++.<++++++++++.<+++++[<+++++>-]<+>>>.<[>>[>.]<[>+>+<<-]>+.>[<<+> >-]<[<.]<-]>>[>[>]<[-]<[<]>>[.>]<<[.<]>]
Slightly more readable version:
----[---->+<]>++.<
++++++++++.<
+++++[<+++++>-]<+
>>
>.<
[
>>[>.]<
[>+>+<<-]
>+.>
[<<+>>-]
<[<.]<
-
]
>>
[
>[>]<
[-]
<[<]>
>[.>]<<[.<]>
]
Explanation possibly to come.
K4, 28 bytes
Solution:
-1 .Q.A@f'(f:{t,x,|t:!x})25;
Explanation:
Define a function to create a palindrome range, create a palindrome range of 0..25..0, and then apply it to each in the list:
-1 .Q.A@f'(f:{t,x,|t:!x})25; / the solution
-1 ; / print to stdout and swallow return value (-1)
( ) / do together
f:{ } / define function f as...
!x / range 0..x-1
t: / save as variable t
| / reverse it
x, / join with x
t, / join with t
25 / perform f[25] => 0 1 2.. 25 24.. 1 0
f' / apply f to each of these
.Q.A@ / apply (@) these indices to the alphabet A..Z
K4 isn't on TIO, but there's oK which is similar... Try it online!
Canvas, 6 bytes
Z[│]──
Explanation:
Z push the alphabet
[ ] map over the prefixes
│ palindromize horizontally
── palindromize vertically without mirroring characters
VBA, 91 Bytes
Anonymous VBE immediate window function that takes no input and outputs the alphabet triangle to the VBE immediate window
For i=-25To 25:For j=0To-Abs(i)+25:s=s+Chr(65+j):Next:?s;StrReverse(Left(s,j-1)):s="":Next
-1 byte for use of ; over & in ? statement
Kotlin, 99 93 88 bytes
(('A'..'Y')+'Z'.downTo('A')).map{println((('A'..it-1)+it.downTo('A')).joinToString(""))}
That's still longer than I expected but I doubt I'll be able to golf it further.
Factorisation doesn't save the day, best I could do is 93 bytes :
fun r(a:Char,b:Char)=(a..b-1)+b.downTo(a)
r('A','Z').map{println(r('A',it).joinToString(""))}
Mathematica 59 bytes
Column@FromCharacterCode[#@#@26+64]&[#-Abs@Range[1-#,#-1]&]
Recursiva, 12 bytes
{pB26'PpZ0(}
Explanation:
{pB26'PpZ0(}
{ - For each
p - Palindromize [1,2..26,25,24...1]
B26 - Range 26 [1,2....26]
' - iteration command begin
P - Print
p - palindromize 'ABCDEDCBA'
Z0(} - Slice upper-case alphabet "(" from 0 to current count "}"
for example if }=5 'ABCDE'
SOGL V0.12, 10 bytes
øZ{⁴Κ}¹╬,k
Explanation:
ø push an empty string
Z{ } for each character in the alphabet do
⁴ duplicate the item before the top item
Κ reverse add to that
or simpler - on each iteration creates a duplicate of ToS but with the current character appended.
¹ wrap the stack in an array
╬, quad-palindromize without spacing to a square
k remove the 1st line
The last k could be removed if the question allowed leading newlines.
Python, 156 bytes
Not impressive, but I'm proud of myself because I'm a noob:
def p(k):
x=k-1
while x>-k:
print(chr(64+(k-abs(x))),end="")
x-=1
q=25
while q>-27:
p(26-abs(q))
print()
q-=1
Common Lisp, 175 bytes
(let*((a"abcdefghijklmnopqrstuvwxyz")(f"~a~a~%")(b(reverse a)))(#1=dotimes(i 26)(#2=format t f(#3=subseq a 0 i)(#3#b(- 25 i))))(#1#(i 25)(#2#t f(#3#a 0(- 24 i))(#3#b(1+ i)))))
Ungolfed version:
(let* ((a "abcdefghijklmnopqrstuvwxyz") ; define the alphabet
(b (reverse a))) ; and reverse it
(dotimes (i 26) ; print first half, 26 lines
(format t "~a~a~%" (subseq a 0 i) (subseq b (- 25 i))))
(dotimes (i 25) ; print second half
(format t "~a~a~%" (subseq a 0 (- 24 i)) (subseq b (1+ i)))))
Java 131 bytes
Without using String (131 bytes)
public static void main(String[] args) {
for(int i = 0 ,k=1; i>-1; i+=k){
for(int c= 65, d = 1; c>64;){
d = d>-1 & c < 65+i?1:-1;
System.out.print((char)c+((c+=d)<65?"\n":""));
}
k = k>-1 & i < 25?1:-1;
}
}
Codegolfed
for(int i=0,k=1;i>-1;k=k>-1&i<25?1:-1,i+=k)for(int c=65,d=1;c>64;d=d>-1&c<65+i?1:-1,System.out.print((char)c+((c+=d)<65?"\n":"")));
With String(173 bytes)
String a="abcdefghijklmnopqrstuvwxyz";
for(int i = 1 ,k=1; i>0; i+=k==1?1:-1){
System.out.println(a.substring(0,i)+new StringBuilder(a).reverse().substring(27-i));
k = k>-1 & i < 26?1:-1;
}
Codegolfed
String a="abcdefghijklmnopqrstuvwxyz";for(int i=1,k=1;i>0;k=k>-1&i<26?1:-1,System.out.println(a.substring(0,i)+new StringBuilder(a).reverse().substring(27-i)),i+=k==1?1:-1);
Thanks to manatwork and Kevin Cruijssen
Clojure, 111 bytes
#(let[f(fn[i](concat(range i)(range i -1 -1)))](doseq[i(f 25)](println(apply str(for[j(f i)](char(+ j 65)))))))
A function which prints the result. f is an utility function which creates the sequence from 0 to i and back to 0.
CJam, 29 bytes
'[,65>:A,{)A<_W%(;+}%_W%(;+N*
Pretty simple.
Explanation:
'[,65>:A e# Get the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ" and store in A
,{ e# For i in range(26), collecting j:
) e# j += i + 1
A< e# j = a[:i]
_W% e# k = reverse(j)
(; e# k.pop()
+ e# j += k
}% e# End
_W% e# Duplicate and reverse
(; e# Pop()
+ e# Append
N* e# Join with newlines
PHP, 78 Bytes
foreach(range(A,Z)as$r)$o.="\n$t".strrev($t.=$r);echo$o.substr(strrev($o),51);
Racket 327 bytes
(define(sr s)(list->string(reverse(string->list s))))(let loop((n 0)(s"A")(ol'("A")))(let*((st string)(mr(floor(/(string-length s)2)))
(mc(string-ref s mr))(ss(substring s 0 mr))(ns(string-append ss(st mc)(st(integer->char(+ 65(add1 n))))(st mc)(sr ss))))(if(< n 25)
(loop(add1 n)ns(cons ns ol))(append(reverse ol)(rest ol)))))
Ungolfed:
(define (f)
(define (sr s) ; sub-fn to reverse a string;
(list->string
(reverse
(string->list s))))
(let loop ((n 0)
(s "A")
(ol '("A")))
(let* ((st string)
(mr (floor(/(string-length s)2)))
(mc (string-ref s mr))
(ss (substring s 0 mr))
(ns (string-append
ss
(st mc)
(st (integer->char (+ 65(add1 n))))
(st mc)
(sr ss))))
(if (< n 25)
(loop (add1 n)
ns
(cons ns ol))
(append(reverse ol)(rest ol))
))))
Testing:
(f)
Output:
'("A"
"ABA"
"ABCBA"
"ABCDCBA"
"ABCDEDCBA"
"ABCDEFEDCBA"
"ABCDEFGFEDCBA"
"ABCDEFGHGFEDCBA"
"ABCDEFGHIHGFEDCBA"
"ABCDEFGHIJIHGFEDCBA"
"ABCDEFGHIJKJIHGFEDCBA"
"ABCDEFGHIJKLKJIHGFEDCBA"
"ABCDEFGHIJKLMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNONMLKJIHGFEDCBA"
"ABCDEFGHIJKLMNMLKJIHGFEDCBA"
"ABCDEFGHIJKLMLKJIHGFEDCBA"
"ABCDEFGHIJKLKJIHGFEDCBA"
"ABCDEFGHIJKJIHGFEDCBA"
"ABCDEFGHIJIHGFEDCBA"
"ABCDEFGHIHGFEDCBA"
"ABCDEFGHGFEDCBA"
"ABCDEFGFEDCBA"
"ABCDEFEDCBA"
"ABCDEDCBA"
"ABCDCBA"
"ABCBA"
"ABA"
"A")
J, 26 23 22 bytes
f(f=:,1}.|.)\u:65+i.26
Explanation
,1}.|. Monad f: Input: A
|. Reverse the items in A
1}. Drop the first item in the reversed A
, Join A and the previous
f(f=:,1}.|.)\u:65+i.26
i.26 Create the range [0, 1, ..., 25]
65+ Add 65 to each
u: Convert to characters to get 'A..Z'
f=:,1}.|. Define a verb f
( )\ Call f monadically on each prefix of 'A..Z'
f Call f again on that result
Rust, 120 bytes
fn main(){for j in -25i8..26{let k=25-j.abs();for i in -k..k+1{print!("{}",(65+k-i.abs())as u8 as char);}println!("");}}
My first attempt at codegolfing in Rust... codegolfing in anything, really. A straightforward attempt, just using for loops and abs().
fn main() {
for j in -25i8..26 {
let k=25-j.abs();
for i in -k..k+1{
print!("{}",(65+k-i.abs())as u8 as char);
}
println!("");
}
}
JavaScript (ES6), 89 bytes
R=(n,s=10,c=s.toString(36))=>n?c+R(n-1,s+1)+c:c
C=(n=0,r=R(n))=>n<25?r+`
`+C(n+1)+`
`+r:r
Not the shortest, but I wanted to try my hand at recursion. Call with C().
R, 127 125 bytes
k=cat;L=LETTERS;for(i in 1:26)k(c(L[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))
Not completely satisfied with this solution, especially the two for loops, but couldn't come with something better !
LETTERS contains the uppercase letters.
Ungolfed :
for(i in 1:26){
cat(c(LETTERS[1:i],LETTERS[(i-1):0],"\n"))
}
for(i in 1:26){
cat(c(LETTERS[0:(26-i)],LETTERS[ifelse((25-i)>=0,25-i,0):0],"\n"))
}
ifelse is a shorter way for unsing if... else... and works this way : ifelse(condition,action if TRUE, action if FALSE)
An other 125 bytes' solution :
for(i in 1:26)(k=cat)(c((L=LETTERS)[1:i],L[(i-1):0],"\n"));for(i in 1:26)k(c(L[0:(26-i)],L[ifelse((25-i)>=0,25-i,0):0],"\n"))
Logo, 232 207 196 190 bytes
Did somebody say triangles?
Get out your compass and protractor, and let's do this the graphical way. The geometry uses an equilateral triangle to align the results. I previously had an isosceles triangle, but it involved too many decimal places. This change also compacted the output, reducing the amount of screen prep and font changing I had to do.
I used the Calormen online interpreter to flesh this one out. If you don't have enough screen real estate, it's going to wrap, but you can also fiddle with some numbers to take care of that. I used the "F11" full-screen mode on my browser.
ht
pu
to r:n:b:l repeat:n[rt:b label char 90-:n lt:b fd:l] end
to t:s
fd 12 rt 120 bk 6
repeat 2[r:s 90 12]
repeat 2[rt 120 r:s 90-heading 24]
end
rt 90 label "Z lt 210
repeat 25[t repcount]
The r procedure draws a line of n characters. The character is determined automatically depending on how many segments it is told to use. The b parameter tells it how much to temporarily rotate so that the letters are pointing in the right direction. The l parameter determines the linear distance between letters.
The t procedure steps to the next position and calls the r function a four times to create a triangle, rotating when appropriate. I called it twice for the vertical side because that took fewer bytes than calling it once with special handling. The end of the procedure positions the turtle for start of the next triangle, one step above.
Z is a special case, so we just print it directly and rotate as if we had just finished a triangle. Finally, t is called 25 times.
Brachylog, 37 29 bytes
Credits to Fatalize for his assistance throughout.
4 bytes thanks to Fatalize, and inspiration for another 4 bytes.
@A:1&e:"a"yr:1&cw@Nw\
:Lc.r.!
Predicate 0 (Main predicate)
@A:1&e:"a"yr:1&cw@Nw\
@A:1& Apply predicate 1 to @A, which is
basically "abcdefghijklmnopqrstuvwxyz"
e Choose one element from the result (choice point)
:"a"yr generate substring from element to "a"
:1& apply predicate 1
c concatenate
w write to STDOUT
@Nw write "\n" to STDOUT
\ Backtrack to last choice point to choose
another element until there is no more
choice left, then halt.
Predicate 1 (Auxiliary predicate)
This basically builds a palindrome from the given string.
:Lc.r.!
:Lc. output is [input:L]
.r. output reversed is still output
! stop searching after the first output
Clojure, 182 bytes
(let[d dec w str c char n \u000A](defn p[x s](if(= x 65)s(p(d x)(w(c(d x))s(c(d x))))))(println(#(if(= % 65)%2(recur(d %)(w(p(d %)(c(d %)))n %2(p(d %)(c(d %)))n)))90(w(p 90 "Z")n))))
My first codegolf :). There is probably a much easier way to do it, but I am very new to clojure.
Python 3, 123 101 98 bytes
for i in range(1,52):r=[chr(j+65)for j in range(abs(26*(i//26)-i%26))];print(''.join(r+r[-2::-1]))
lol I am really bad at this
thanks @Leaky Nun for the r[-1::-1] == r[:-1][::-1] tip (:
Alternative solution, with help from @Leaky Nun (8885 bytes)
for i in range(1,52):r=[*map(chr,range(65,91-abs(i-26)))];print(''.join(r+r[-2::-1]))
R, 63 61 59 bytes
for(i in c(1:26,25:1))cat(LETTERS[c(1:i,i:1-1)],"
",sep="")
Helpfully LETTTERS[0] doesn't return any characters.
Edit: lost one thanks to @leakynun
Edit: two more thanks to @plannapus
HTML + CSS, 884 characters
(763 characters HTML + 121 characters CSS)
Just expanding Leaky Nun's comment on MonkeyZeus's answer. (Though I might misread the comment…)
p{margin:0}p:before{content:"ABCDEFGH"}p:after{content:"HGFEDCBA"}a:before{content:"IJKLMNOP"}a:after{content:"PONMLKJI"}
<pre>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
<p>I</p><p>IJI</p><p>IJKJI</p><p>IJKLKJI</p><p>IJKLMLKJI</p><p>IJKLMNMLKJI</p><p>IJKLMNONMLKJI</p><p>IJKLMNOPONMLKJI</p><p><a>Q</p><p><a>QRQ</p><p><a>QRSRQ</p><p><a>QRSTSRQ</p><p><a>QRSTUTSRQ</p><p><a>QRSTUVUTSRQ</p><p><a>QRSTUVWVUTSRQ</p><p><a>QRSTUVWXWVUTSRQ</p><p><a>QRSTUVWXYXWVUTSRQ</p><p><a>QRSTUVWXYZYXWVUTSRQ</p><p><a>QRSTUVWXYXWVUTSRQ</p><p><a>QRSTUVWXWVUTSRQ</p><p><a>QRSTUVWVUTSRQ</p><p><a>QRSTUVUTSRQ</p><p><a>QRSTUTSRQ</p><p><a>QRSTSRQ</p><p><a>QRSRQ</p><p><a>QRQ</p><p><a>Q</a></p><p>IJKLMNOPONMLKJI</p><p>IJKLMNONMLKJI</p><p>IJKLMNMLKJI</p><p>IJKLMLKJI</p><p>IJKLKJI</p><p>IJKJI</p><p>IJI</p><p>I</p>ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A
Javascript (ES6), 113 bytes
i=>{for(i=0;i<51;i++,console.log(L))for(j=s=i<26?i:50-i,L="";j>=0;)k=String.fromCharCode(65+j),L=k+(j---s?L+k:L)}
Thanks to manatwork for pointing me to a tip written by William Barbosa to reduce by a byte.
JavaScript (177 175 chars)
This is my best attempt at golfing this problem. I cannot find a way to do this with fewer characters
o='';
for(i=1;i<=26;i++){
l='';
for(j=1;j<=i;j++){
l+=String.fromCharCode(j+64);
}
o+=l+l.slice(0,l.indexOf(l.slice(-1))).split('').reverse().join('')+"\n";
}
console.log(o);
C#, 289 215 206 190 179 171 159 157 156 153 147 bytes
(n,i,s)=>{s=new string[51];for(i=0;i<26;){for(n=65;n-65<i;)s[i]+=(char)n++;for(;n>64;)s[i]+=(char)n--;s[50-i]=s[i++];}return string.Join("\n",s);};
Saved 3 bytes thanks to VisualMelon
Saved 6 bytes thanks to mdfst13
Formatted version:
(n,i,s)=>
{
s=new string[51];
for(i=0;i<26;)
{
for(n=65;n-65<i;)
s[i]+=(char)n++;
for(;n>64;)
s[i] += (char)n--;
s[50-i]=s[i++];
}
return string.Join("\n",s);
};
156 byte version (when the irrelevant whitespace is removed) of counting backwards, uses a similar concept to the above method but does so in reverse.
(n, i, s) =>
{
s = new string[i = 51];
for (; --i > 24;)
{
for (n = 65; i + n < 116;)
s[i] += (char)n++;
for (n = 50 - i + 64; n > 64;)
s[i] += (char)n--;
s[50 - i] = s[i];
}
return string.Join("\n", s);
};
JavaScript (ES6), 81 bytes
[...'ZYXWVUTSRQPONMLKJIHGFEDCBA'].reduce((p,c)=>c+`
`+p.replace(/^|$/gm,c)+`
`+c)
Javascript (ES5), 105 bytes
Beating all other ES6 answers using some good ol' vanilla JS looping!
for(a="",n=g=1;n++<52;n<27?g++:g--){for(z=x=0;z++<g*2-1;z<g?x++:x--)a+=String.fromCharCode(65+x);a+="\n"}a
I could save 1 byte by using ES6 and changing
a+="\n"
to
a+=`
`
but nah.
R, 71 69 bytes
L=LETTERS;for(i in c(1:26,25:1))cat(c(L[1:i],L[i:1][-1]),"\n",sep="")
See here on an online interpreter.
Edit: moved LETTERS outside the loop in order to avoid the curly brackets.
MATLAB, 53 Bytes
MATLAB is not made for strings, so this needs some looping. I haven't found a faster way to create a list 1 2 3 4 3 2 1, than [1:4,3:-1:1], which seems really verbose.
Anyway, it's only beaten by 11/55 other submissions, and most of those are golfing languages.
for i=[1:26,25:-1:1]
disp(['',64+[1:i,i-1:-1:1]])
end
Python, 73 71 bytes
Thanks to @xnor for the recursion
f=lambda x=66,s='A',t='':x/92*t or t+f(x+1,s+chr(x),s+s[-2::-1]+"\n")+t
Explanation
- Parameters:
xis the ascii value of the next letter in the alphabetsis an accumulator for the alphabettis a line in the triangle (ies+s backwards)
- Return:
tif the alphabet is done (ie we're at the center) - Else:
t+f(...)+twith:xincrementedsappended with the next lettertreset tos+s backwards+\n
Update
- -2 [16-08-05] Remove leading
\n(+1) and shortened conditional (-3) all thanks to @xnor
Guile, 188 bytes
(define(t d e)(if(= e 27)(apply string-append(map list->string(append(reverse(cdr d))d)))(t(cons(let((a(map integer->char(iota e #x41))))(append a(cdr(reverse a))'(#\newline)))d)(1+ e))))
Or in a readable form:
(define (triangle done depth)
(if (= depth 27)
(apply string-append
(map list->string
(append (reverse (cdr done))
done)))
(triangle
(cons (let ((alphabet (map integer->char (iota depth #x41))))
(append alphabet (cdr (reverse alphabet)) '(#\newline)))
done)
(1+ depth))))
Call the program with (triangle '() 1) or (t '() 1), note that srfi-1 needs to be loaded.
The program creates a list of the chars in the alphabet, from a to the last letter in the current line. It then takes that lists, reverses it and removes the original last character, appends the two lists and adds a newline character at the end. It then does that 26 times, from A to Z. It then converts the lists to strings and concats them.
The program returns a string, which then should be passed to display, but this wasn't needed in the challenge.
PHP, 80 83 bytes
Making half of the triangle then print it in reverse did the trick.
for($a="A";$a<"Z";$b.=$a++)$c.=$b.$a.strrev($b)."
";echo"$c{$b}Z".strrev($c.$b);
Python, 74 bytes
def f(x=66,s='A'):
t=s+s[-2::-1];print t
if x<91:f(x+1,s+chr(x));print t
A Python 2 function that prints and takes no arguments. The key idea is to generate the triangular there-and-back pattern with recursion. First consider this simpler function that prints the letters 'A' up to 'Z' and down back to 'A':
def f(x=65):
t=chr(x);print t
if x<90:f(x+1);print t
The function first prints "A" (char-code 65), then recurses to print "B" (66) and so on to "Z" (90). From there, it stops recursing. On the way popping back down the recursive stack, it prints whatever character t it printed at the same layer, from "Y" back to "A".
The main code does the same, except it accumulates into s the string of letters so far, and prints the up-and-down string s+s[-2::-1].
Thanks to xsot for 2 bytes.
In Python 3, the same thing is a byte shorter (73 bytes) by putting everything on one line.
def f(x=66,s='A'):t=s+s[-2::-1];print(t);x>90or[f(x+1,s+chr(x)),print(t)]
Python, 109 bytes
z="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
def a(x):v=z[:x]+z[x-26::-1]+"\n";return v+a(x+1)+v if x<25 else v
print a(0)
Build up a string with a recursive call in the middle to build the triangle out. Might come back to try and get it <100.
R, 95 bytes
L=LETTERS;cat("A\n");for(i in 2:50)cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n');cat("A\n")
Ungolfed:
L=LETTERS; #Took idea from @Frederic, I apologize if I shouldn't (first time posting)
cat("A\n")
for(i in 2:50)
{
cat(L[1:(26-abs(i-26))],L[(25-abs(i-26)):1],'\n')
}
cat("A\n")
Basically, the formula in the cat function in the for loop is a transformation on the absolute value function, mapping n -> n for Letters 2 through 26 and then mapping Letters 27 -> 25, 28 -> 24, ..., 50 -> 2. I don't think it would work if I included the 'A' in this formula, which is why I printed it out separately.
VBA, 94 bytes
Function T:For j=-25To 25:k=25-Abs(j):For i=-k To k:T=T &Chr(65+k-Abs(i)):Next:T=T &vbLf:Next
Call in Immediate window with ?T
Just to explain what's going on: I use Abs function twice, to reflect both the alphabet traverse and the line length. It's well suited to the task because of the single extreme value in both cases, which corresponds to the zero crossing of the pre-Abs variable.
As a simple set of commands in VBA Immediate window, rather than a program or function, the following would need 72 bytes:
For j=-25To 25:k=25-Abs(j):For i=-k To k:?Chr(65+k-Abs(i));:Next:?:Next
(with thanks to @GuitarPicker)
HTML, 1412 bytes
<pre>A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A</pre>
C#, 162 bytes
void p(){for(int i=1;i<54;i++){var a=Enumerable.Range(65,i>27?54-i:i).Select(n=>(char)n);Console.WriteLine(new string(a.Concat(a.Reverse().Skip(1)).ToArray()));}}
Java 169 156bytes
String a="abcdefghijklmnopqrstuvwxyz";
public void alphabetTriangle(){
for(int i=0;++i<27;){
System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));
}
}
Golfed
String a="abcdefghijklmnopqrstuvwxyz";void l(){for(int i=0;++i<27;){System.out.println(a.substring(0,a)+new StringBuilder(a).reverse().substring(1,-i+1));}}
It is actually same as the batch solution with some shortcuts
Thanks to @Value Ink for saving 15 bytes by shortening the method name.
QBasic, 151 122 bytes
Really just for fun (via QB64) - it doesn't golf well
Taking some ABS() inspiration from Joffan's VBA answer but applying it differently:
FOR i=-25 TO 25
FOR n=0 TO 25-abs(i)
s$=s$+chr$(n+65)
IF n THEN t$=t$+chr$(90-abs(i)-abs(n))
NEXT
? s$+t$
s$=""
t$=""
NEXT
Previously:
FOR i=0 TO 25
p(i)
NEXT
FOR i=0 to 25
p(25-i)
NEXT
SUB p(i)
FOR n=0 TO i
s$=s$+chr$(n+65)
IF n THEN t$=t$+chr$(65+i-n)
NEXT
? s$+t$
s$=""
t$=""
END SUB
Mathematica 98 96 92 bytes
There has to be a shorter way, even in Mathematica.
6 bytes saved thanks to Martin Ender.
r=Reverse@*Most; Print/@FromCharacterCode@Join[t=Join[s=Range[65,64+k],r@s]~Table~{k,26},r@t]
Racket, 147 bytes
At least it beats QBasic.
((λ(x)(display(string-join(x(build-list 26(λ(n)(list->string(map integer->char(x(range 65(+ 66 n))))))))"\n")))(λ(m)(append m(cdr(reverse m)))))
Batch, 226 224 bytes
@set z=ABCDEFGHIJKLMNOPQRSTUVWXYZ
@set a=YXWVUTSRQPONMLKJIHGFEDCBA
@for /l %%i in (0,1,25)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%
@for /l %%i in (24,-1,0)do @call echo %%z:~0,%%i%%%%z:~%%i,1%%%%a:~-%%i,%%i%%
Edit: Saved 2 bytes thanks to @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ.
C, 93 bytes
Call f() without arguments.
g(l,n){putchar(l);n?g(l+1,--n),putchar(l):0;}f(n){for(n=-26;++n<26;puts(""))g(65,25-abs(n));}
Pyth, 13 bytes
L+bt_bjyyM._G
L+bt_b Concatenates a thing with its reverse without the first element. Define as y.
._G: Form all prefixes of the alphabet
yM: Apply y to each element.
y: Apply y to the list as a whole.
j: Join on newlines.
Python 2, 98 bytes
This is what I think is a unique approach in that it recursively builds up half a line at a time and calls the alphabet-building function twice to build a full line. Golfing suggestions welcome.
f=lambda a:a and f(a-1)+chr(64+a)or""
for i in range(-26,27):print f(26-abs(i))+f(27-abs(i))[::-1]
Cheddar, 102 96 79 69 67 bytes
17 bytes thanks to Downgoat, and inspiration for 10 more.
"A"+(2@"27+@"(25|>1)).bytes.map(i->65@"(64+i)+@"((64+i)|>65)).vfuse
The fact that strings can concatenate but not arrays means that I would have to convert the two ranges to strings, concatenate, and then convert back to arrays.
Also, the fact that vfuse produces a leading newliens means that I would need to generate the first line manually and then concat to the rest.
@" as a dyad (two-argument function) can convert to string directly, but does not work for reversed range (if first argument is bigger than the second).
Range was half-inclusive. After the bug-fix it became inclusive.
Usage
cheddar> "A"+(2@"27+@"(25|>1)).bytes.map(i->(65@"(64+i)+@"((64+i)|>65))).vfuse
"A
ABA
ABCBA
ABCDCBA
ABCDEDCBA
ABCDEFEDCBA
ABCDEFGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A"
Cheddar, 55 bytes (non-competing)
In the latest version with all the fixes, the answer is:
(|>25+24|>0).map(i->65@"(65+i)+(i?(64+i)@"65:"")).vfuse
but it was made after the challenge.
Python 2.7, 136 bytes
x=[chr(y) for y in range(65,91)]
for y in range(25):print ''.join(x[:y]+x[y::-1])
for y in range(25,-1,-1):print ''.join(x[:y]+x[y::-1])
Jelly, 16 bytes
ŒRAạ
25ÇÇ€‘ịØAj⁷
This uses the same method in my Python answer.
Explanation
ŒRAạ Define a helper link. Input: n
ŒR Create the range [-abs(n), , ..., 0, ..., abs(n)]
A Take the absolute value of each
ạ Return the absolute difference between each value and n
25ÇÇ€‘ịØAj⁷ Main link. No arguments
25 The constant 25
Ç Call the helper link on 25 to get [0, 1, ..., 25, ..., 1, 0]
Ç€ Call the helper link on each value in the previous
‘ Increment every value
ØA The alphabet (the string 'A..Z')
ị Select the char at each index in the alphabet
j⁷ Join them using newlines and return
Swift 2.2, 157 142 Bytes
let t={(l:Int)in[Int](1..<l)+[Int](l.stride(to:0,by:-1))}
for x in(t(n).map{t($0).map{"\(UnicodeScalar($0+64))"}.reduce(""){$0+$1}}){print(x)}
ungolfed:
let makeTriangleArray = {(limit: Int) -> [Int] in
return [Int](1 ..< limit) + [Int](limit.stride(to: 0, by: -1))
}
let n = 26
let lines = makeTriangleArray(n).map{
makeTriangleArray($0).map{String(UnicodeScalar($0 + 64))}
.reduce(""){ $0 + $1}
}
for line in lines {
print(line)
}
157 bytes:
let t={(l:Int)in[Int](1..<l)+[Int](l.stride(to:0,by:-1))}
print(t(n).map{t($0).map{"\(UnicodeScalar($0+64))"}.joinWithSeparator("")}.joinWithSeparator("\n"))
ungolfed:
let makeTriangleArray = {(limit: Int) -> [Int] in // "called t" above
return [Int](1 ..< limit) + [Int](limit.stride(to: 0, by: -1))
}
let n = 26
let s = makeTriangleArray(n).map{
makeTriangleArray($0).map{String(UnicodeScalar($0 + 64))}
.joinWithSeparator("")
}.joinWithSeparator("\n")
print(s)
Python 2, 117 111 105 100 bytes
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"*2
for i in range(51):print(s[:-i-1]+s[-i-3::-1],s[:i]+s[i::-1])[26>i]
Thanks to @LeakyNun and @manatwork for pointing out a few byte saves.
Non-Golfed:
import string
def print_alphatriangle(n):
offset = 1
tail_offset = 3
alpha = string.ascii_uppercase * n
for i in range(len(alpha) - offset):
if len(alpha) / 2 > i:
print alpha[:i] + alpha[i::-offset]
continue
print alpha[:-i-offset] + alpha[-i-tail_offset::-offset]
This method works simply by string splicing an alphabet string that is concatenated together. Depending on whether i has reached a mid-way point of the string, it then starts to print out decreasing strings.
Vim, 37 bytes
:h<_↵↵↵YZZPP$xqqxYpGP√2G$A♥-€k$q24@qJ
Legend
↵ = Return
√ = Ctrl+V
♥ = Ctrl+R
€ = Escape
Powershell, 61 52 bytes
Thanks to TimmyD for saving 9 bytes!
65..90+89..65|%{-join[char[]]((65..$_-ne$_)+$_..65)}
Loops through ASCII values for capital letters forwards, then backwards. For each number, this creates an array of the first X numbers, removes the X-1st number, then adds the reverse of the first X numbers, which is all then cast to chars and joined into a string.
Retina, 90 88 86 76 bytes
I'm sure it can be made shorter, maybe by using non-verbose replacements and simply outputting at the end. (I tried. I don't think I can do it shorter that way.)
:`
A
A
ABA
{:`
(.)([^Z]\1)
$1$2$2
}T1`__L`L`(?<=(.)[^Z])\1
+:`(.).\1|^A$
$1
Thanks to LeakyNun for 14 bytes off
Javascript(using external library-Enumerable), 135 bytes
_.Range(1,51).WriteLine(x=>(g=_.Range(65,x>25?52-x:x)).Write("",y=>(w=String.fromCharCode)(y))+(g.Reverse().Skip(1).Write("",y=>w(y))))
Link to the library: https://github.com/mvegh1/Enumerable
Code explanation: Create a range of ints starting at 1, for a count of 51. For each, write a line according to complex pred. Do some JS wizardry with global variables and caching...and voila. For each int in WriteLine, we are creating the left hand range of ints and storing into global "g", and String Joining (Write) with "" delimiter and mapping each int to the String mapping to the int char code. Then, we concat the right hand side by taking the reversal of that sequence (and skipping the first element because that will match the last element of the original order...), writing with the same logic. EDIT: Updated the internals of Write in the library. An empty sequence will write an empty string instead of null now. This also shaved 15 bytes off the answer
C, 272 247 234 230 144 137 bytes:
(Saved many bytes (272 -> 230) in my previous method thanks to great golfing tips & tricks from sigalor!)
(Saved nearly 100 bytes (230 -> 144) by switching to a better method.)
main(q,i,e,x){for(q=0;q<51;q++){i=q>25 ? 25-(q-25):q;for(e=65;e<66+i;e++)printf("%c",e);for(x=64+i;x>64;x--)printf("%c",x);printf("\n");}}
My first answer ever in C. I just started self-learning it recently, so let's see how it goes.
JavaScript (ES6), 122 bytes
_=>(s='',r=x=>[...x].reverse().join``,t=[...'ABCDEFGHIJKLMNOPQRSTUVWXYZ'].map(c=>s+c+r(s,s+=c)).join`
`)+r(t.slice(0,650))
As an anonymous function. (4 more bytes if you want to alert it)
Test
document.write('<pre>'+(
_=>(
s='',
r=x=>[...x].reverse().join``,
t=
[...'ABCDEFGHIJKLMNOPQRSTUVWXYZ']
.map(c=>
s+c+r(s,s+=c)
).join`\n`
)+r(t.slice(0,650))
)());
JavaScript (ES6), 141
for(a=65,q=[],z=[];a<91;z.push(a++))q.push(String.fromCharCode(...z,a,...[...z].reverse()))
a=q.pop(),alert([...q,a,...q.reverse()].join`\n`)
TSQL, 159 bytes
DECLARE @ varchar(52)='ABCDEFGHIJKLMNOPQRSTUVWXY',@o varchar(max)SELECT @+='Z'+REVERSE(@)+'
',@o=@
WHILE''<@
SELECT @=STUFF(@,LEN(@)/2,2,''),@o=@+@o+@
PRINT @o
Dyalog APL, 18 bytes
↑(⊣,⌽)(⊣,1↓⌽)¨,\⎕a
bash, 80 bytes
printf -v a %s {A..Z};for i in {1..26} {25..1};{ echo ${a::i}`rev<<<${a::i-1}`;}
///, 208 bytes
/'/\/\///+/BA
AB'-/DC+CD'&/FE-EF')/HG&GH'=/JI)IJ'|/LK=KL'7/NM|MN'1/PO7OP'q/RQ1QR'p/TSqST'6/VUpUV'[/XW6WX/A
A+C+C-E-E&G&G)I)I=K=K|M|M7O7O1Q1QqSqSpUpU6W6W[Y[YZY[Y[W6W6UpUpSqSqQ1Q1O7O7M|M|K=K=I)I)G&G&E-E-C+C+A
A
Not winning of course, but here it is, predating Martin Ender...
Sesos, 27 bytes
0000000: a85ab9 ac5daa f8b1c7 785f9b b961f7 665c1b 73ccfc .Z..]....x_..a.f\.s..
0000015: c01ecb 987303 ....s.
Try it online! Check Debug to see the generated SBIN code.
Sesos assembly
The binary file above has been generated by assembling the following SASM code.
add 65, rwd 1, add 10, rwd 2, add 25
jmp
fwd 3
jmp
put, fwd 1
jnz
rwd 1
jmp
fwd 1, add 1, fwd 1, add 1, rwd 2, sub 1
jnz
fwd 2
jmp
rwd 2, add 1, fwd 2, sub 1
jnz
rwd 1, add 1, rwd 2
jmp
put, rwd 1
jnz
rwd 1, sub 1
jnz
fwd 3
jmp
jmp
put, fwd 1
jnz
rwd 1, get, rwd 1
jmp
put, rwd 1
jnz
fwd 2
; jnz (implicit)
Python 2, 86 85 bytes
n=0;exec'x=25-abs(n-25);print bytearray(65+x-abs(y-x)for y in range(2*x+1));n+=1;'*51
This follows a simple process. First, create the range [0, 1, ..., 24, 25, 24, ..., 1, 0]. Then, for each value x in that range, create another range [0, 1, ..., x, ..., 1, 0] and map each of those values to a character in 'A..Z'. Finally, print each string of characters.
Ruby, 71 bytes
s=*?A..?Y
s+=[?Z]+s.reverse
puts s.map{|e|k=[*?A...e]*'';k+e+k.reverse}
Jelly, 16 13 bytes
Ṗ;Ṛ
ØAḣJÇ€Çj⁷
Thanks to @LeakyNun for golfing off 3 bytes!
How it works
Ṗ;Ṛ Helper link. Argument: A (array)
Ṗ Pop; yield A without its last element.
Ṛ Reversed; yield A with inverted order.
; Concatenate the results to both sides.
ØAḣJÇ€Çj⁷ Main link. No arguments.
ØA Alphabet; set link argument and return value to "A...Z".
J Indices; yield [1, ..., 26].
ḣ Head; take the first, the first two, etc. elements of the alphabet.
This yields ["A", AB", ..., "A...Z"].
Ç€ Apply the helper link to each string.
Ç Apply the helper link to the array itself.
j⁷ Join, separating by linefeeds.
Haskell, 58 bytes
f x=init x++reverse x
t=unlines$f[f['A'..c]|c<-['A'..'Z']]
Defines a function t that returns the output as a string.
f x= define a helper function
init x take the argument minus its last element
++ and concatenate it with
reverse x the argument reversed, producing ex. [a,b,c,b,a] from [a,b,c]
t= define the main function
[ |c<-['A'..'Z']] for every char c from 'A' to 'Z'...
['A'..c] generate the range from 'A' to c
f call the helper function to "reflect" it
f call the helper function on the entire list
unlines$ join on newlines
Python 3, 97 bytes
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
a=[s[:x]+s[x::-1]for x in range(26)]
print('\n'.join(a+a[24::-1]))




