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LMNOPQRQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
ABCDEFGHIJKLMNONMLKJIHGFEDCBA
ABCDEFGHIJKLMNMLKJIHGFEDCBA
ABCDEFGHIJKLMLKJIHGFEDCBA
ABCDEFGHIJKLKJIHGFEDCBA
ABCDEFGHIJKJIHGFEDCBA
ABCDEFGHIJIHGFEDCBA
ABCDEFGHIHGFEDCBA
ABCDEFGHGFEDCBA
ABCDEFGFEDCBA
ABCDEFEDCBA
ABCDEDCBA
ABCDCBA
ABCBA
ABA
A

Specs

  • Extra trailing newlines are allowed at the end of the output.
  • Extra trailing spaces (U+0020) are allowed at the end of each line, including the extra trailing newlines.
  • You can use all lowercase instead of all uppercase, but you cannot print partially lowercase partially uppercase.
  • You can return the text as a function output instead of printing it in a full program.

Scoring

Since this is a triangle, and a triangle has 3 sides, and 3 is a small number, your code should be small in terms of byte-count.

\$\endgroup\$
5
  • 24
    \$\begingroup\$ So many alphabets recently \$\endgroup\$ Commented Aug 3, 2016 at 11:15
  • 1
    \$\begingroup\$ My synesthesia is going hog wild, @downrep_nation \$\endgroup\$ Commented Aug 3, 2016 at 13:33
  • 7
    \$\begingroup\$ "Since a triangle has 3 sides and 3 is a small number, so your code should be small in terms of byte count." seems legitimate \$\endgroup\$ Commented Aug 4, 2016 at 22:00
  • 1
    \$\begingroup\$ Squares of numbers composed only of 1 seems related: 1*1 = 1 ~= A , 11*11 = 121 ~= ABA , 111*111 = 12321 ~= ABCBA ... \$\endgroup\$
    – Caridorc
    Commented Aug 5, 2016 at 13:28
  • 2
    \$\begingroup\$ "Since a triangle has 3 sides and..." Illuminati Confirmed. \$\endgroup\$
    – hyperneutrino
    Commented Oct 28, 2016 at 0:47

96 Answers 96

1
\$\begingroup\$

Canvas, 6 bytes

Z[│]──

Try it here!

Explanation:

Z       push the alphabet
 [ ]    map over the prefixes
  │     palindromize horizontally
    ──  palindromize vertically without mirroring characters
\$\endgroup\$
1
\$\begingroup\$

brainfuck, 109 bytes

+++++[<+++++>-]<+[>>[>[.>]]>++++++++++<<[>>.<]>[<]>--[<++++++++>-]<[+.<]<-]>>,>[.>]++++++++++.[<[.<]>,>[.>]<]

Try it online!

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.

+++++[<+++++>-]<+[>>[>[.>]]>++++++++++.--[<++++++++>-]<[+.<]<-]>>,>[.>]++++++++++.[<[.<]>,>[.>]<]

Try it online!

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

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

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.)
\$\endgroup\$
5
  • \$\begingroup\$ Welcome! Consider adding a detailed explanation. We also like to use online interpreters to allow easy testing of code. I like to use TIO. Here is its Common Lisp interpreter. It also has a permalink tool that can automatically generate markup for an answer post. \$\endgroup\$
    – mbomb007
    Commented Jun 14, 2019 at 19:08
  • \$\begingroup\$ @mbomb007 Thank you for the suggestions, will add the notes. The REPL code is in the title "Common Lisp" ... the TIO looks better, good to know. \$\endgroup\$ Commented Jun 14, 2019 at 19:13
  • \$\begingroup\$ Ah, I didn't notice. Most answers with linked language names are links to the language's home page or documentation. \$\endgroup\$
    – mbomb007
    Commented Jun 14, 2019 at 19:15
  • \$\begingroup\$ @mbomb007 updated with with the link to TIO and with the breakdown. ... Common Lisp is just my newest guilty pleasure, so there is definitely a better approach, just this is my current best try. Looking forward for any suggestions. \$\endgroup\$ Commented Jun 14, 2019 at 19:26
  • 1
    \$\begingroup\$ See if this helps: Tips for golfing is Lisp \$\endgroup\$
    – mbomb007
    Commented Jun 14, 2019 at 19:33
1
\$\begingroup\$

Python 2, 70 bytes

x=25
exec'b=bytearray(range(65,91-abs(x)));print b+b[-2::-1];x-=1;'*51

Try it online!

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

Zsh, 100 96 92 80 57 bytes

Try it online!

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

100 bytes   96 bytes   92 bytes   80 bytes

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

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

Try it online!

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

Julia 1.0, 39 bytes

~c=['A':c;c-1:-1:'A']
!()=join.(.~~'Z')

Try it online!

output is a list of strings

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

MATL, 12 bytes

26Zv"1Y2@Zv)

Try it on MATL Online

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

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

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

Try it at Ideone.

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.

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

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

)());

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

Pyke, 19 16 bytes

27Gm<m[D_t+)RK[X

Try it here!

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

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])
\$\endgroup\$
1
  • \$\begingroup\$ for y in list(range(25)+list(range(24))[::-1]:print ''.join(x[:y]+x[y::-1]) \$\endgroup\$
    – Leaky Nun
    Commented Aug 3, 2016 at 19:34
0
\$\begingroup\$

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]
\$\endgroup\$
0
\$\begingroup\$

Convex, 21 bytes

U{[),U&)\¿@\N]}%)\¿@\

Try it online!

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

Pyth, 13 bytes

L+bt_bjyyM._G

Demonstration

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.

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

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)))))
\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ Trim your function name to one letter. This is code-golf, you don't need verbose function names! \$\endgroup\$
    – Value Ink
    Commented Aug 3, 2016 at 19:41
  • \$\begingroup\$ I allways miss that. Thanks ;) \$\endgroup\$ Commented Aug 3, 2016 at 19:44
  • \$\begingroup\$ I'm sorry, but its not working.. "System.out.println(a.substring(0,a)+new StringBuilder(a).reverse.substring(1,-i+1));" has some errors \$\endgroup\$
    – Syamesh K
    Commented Aug 4, 2016 at 10:51
  • \$\begingroup\$ reverse is a function I suppose and substring does not take string as argument(a.substring(0,a)??) \$\endgroup\$
    – Syamesh K
    Commented Aug 4, 2016 at 10:53
  • \$\begingroup\$ see mine, codegolf.stackexchange.com/a/88646/52212 \$\endgroup\$
    – Syamesh K
    Commented Aug 4, 2016 at 11:42
0
\$\begingroup\$

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.

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

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.

\$\endgroup\$
3
  • \$\begingroup\$ Which version? I get “Wrong number of arguments to #<procedure iota (n)>” with GNU Guile 2.0.11. \$\endgroup\$
    – manatwork
    Commented Aug 5, 2016 at 8:45
  • \$\begingroup\$ Tested with Guile 2.0.12, but that sounds more like srfi-1 isn't loaded. Load it with guile --use-srfi=1 when starting, or as a module with (use-modules (srfi srfi-1)). \$\endgroup\$ Commented Aug 6, 2016 at 9:38
  • \$\begingroup\$ Sorry, that srfi-1 related note said nothing to me. Indeed, this way works fine. BTW, if the code needs module/package/library/unit/whatever loaded or requires command line option to turn on non-default processing mode, those should be included in the code length. Can't tell for sure whether it includes this srfi-1 case, but probably yes. \$\endgroup\$
    – manatwork
    Commented Aug 6, 2016 at 10:11
0
\$\begingroup\$

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

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

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]))
\$\endgroup\$
16
  • \$\begingroup\$ Why do you need lambda :? \$\endgroup\$
    – Leaky Nun
    Commented Aug 5, 2016 at 4:14
  • \$\begingroup\$ was originally this def A(l):r=[chr(i + ord('A'))for i in range(l)];return ''.join(r+r[:-1][::-1]) \$\endgroup\$
    – Jeffrey04
    Commented Aug 5, 2016 at 4:18
  • \$\begingroup\$ for i in range(1,52):print((lambda r:''.join(r+r[:-1][::-1]))([chr(j+65)for j in range(abs(26*(i//26)-i%26))])) \$\endgroup\$
    – Leaky Nun
    Commented Aug 5, 2016 at 4:22
  • \$\begingroup\$ Also, r[:-1][::-1] can be written as r[-1::-1] \$\endgroup\$
    – Leaky Nun
    Commented Aug 5, 2016 at 4:23
  • \$\begingroup\$ You can shift the whole range instead of shifting j, and then you can use map \$\endgroup\$
    – Leaky Nun
    Commented Aug 5, 2016 at 4:33
0
\$\begingroup\$

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.

Ideone

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

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"
  "ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFE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  "ABCDCBA"
  "ABCBA"
  "ABA"
  "A")
\$\endgroup\$
1
  • 1
    \$\begingroup\$ You can shorten your names (i.e. (define (a s) rather than (define (sr s), (let l rather than (let loop). In addition, it was required to output that exact text, so you'd have to join with newlines. \$\endgroup\$ Commented May 1, 2017 at 3:37
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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.

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

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

Try it online!

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)))))
\$\endgroup\$
0
\$\begingroup\$

Recursiva, 12 bytes

{pB26'PpZ0(}

Try it online!

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'
\$\endgroup\$
0
\$\begingroup\$

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

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

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!

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

Japt -R, 14 9 bytes

;Bå+ mê ê

Test it


Explanation

;B            :Uppercase alphabet
  å+          :Cumulatively reduce by addition
     m        :Map
      ê       :  Mirror
        ê     :Mirror
              :Implicitly join with newlines and output
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.