title: Alphabet triangle

text:
# Question
Title: Alphabet triangle
You are to print this exact text:

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

```

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

# Answer
> 41 votes
# Vim, 37 bytes

```
:h<_↵↵↵YZZPP$xqqxYpGP√2G$A♥-€k$q24@qJ

```

## Legend

```
↵ = Return
√ = Ctrl+V
♥ = Ctrl+R
€ = Escape

```

# Answer
> 30 votes
# 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.

# Answer
> 19 votes
## 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

```

# Answer
> 12 votes
# Jelly, ~~16~~ 13 bytes

```
Ṗ;Ṛ
ØAḣJÇ€Çj⁷

```

*Thanks to @LeakyNun for golfing off 3 bytes!*

Try it online!

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

```

# Answer
> 11 votes
## 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)]

```

# Answer
> 8 votes
# 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η€ûû»

```

Try it online!

**Explanation**

```
Aη       # push prefixes of alphabet
  €û     # palendromize each prefix
    û    # palendromize the whole list
     »   # join on newlines

```

# Answer
> 8 votes
# brainfuck, ~~1733~~ ~~121~~ 119 bytes

```
----[---->+<]>++.<++++++++++.<+++++[<+++++>-]<+>>>.<[>>[>.]<[>+>+<<-]>+.>[<<+> >-]<[<.]<-]>>[>[>]<[-]<[<]>>[.>]<<[.<]>]

```

Slightly more readable version:

```
----[---->+<]>++.<
++++++++++.<
+++++[<+++++>-]<+
>>
>.<
[
  >>[>.]<
  [>+>+<<-]
  >+.>
  [<<+>>-]
  <[<.]<
  -
]
>>
[
  >[>]<
  [-]
  <[<]>
  >[.>]<<[.<]>
]

```

Explanation possibly to come.

# Answer
> 6 votes
# Python 3, 97 bytes

```
s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
a=[s[:x]+s[x::-1]for x in range(26)]
print('\n'.join(a+a[24::-1]))

```

Ideone it!

# Answer
> 6 votes
# 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

```

# Answer
> 5 votes
# Ruby, 71 bytes

Try it on repl.it

```
s=*?A..?Y
s+=[?Z]+s.reverse
puts s.map{|e|k=[*?A...e]*'';k+e+k.reverse}

```

# Answer
> 5 votes
# 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.

C it in Action! (Ideone)

# Answer
> 5 votes
# Mathematica 59 bytes

```
Column@FromCharacterCode[#@#@26+64]&[#-Abs@Range[1-#,#-1]&]

```

# Answer
> 5 votes
# \>\<\>, 60 bytes

```
1"AA"1[v
?v:1-:}>:5d*=
o>l  ?!v
{$-}:1[\ao]{:}+::"@Z"@=?;=2*

```

Try it online!

# Answer
> 5 votes
# JavaScript (ES6), 81 bytes

```
[...'ZYXWVUTSRQPONMLKJIHGFEDCBA'].reduce((p,c)=>c+`
`+p.replace(/^|$/gm,c)+`
`+c)

```

# Answer
> 4 votes
## Dyalog APL, 18 bytes

```
↑(⊣,⌽)(⊣,1↓⌽)¨,\⎕a

```

# Answer
> 4 votes
# 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

# Answer
> 4 votes
# (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

```

Output:

# Answer
> 3 votes
# 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

# Answer
> 3 votes
## 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)*

# Answer
> 3 votes
# 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]

```

# Answer
> 3 votes
# TSQL, 159 bytes

```
DECLARE @ varchar(52)='ABCDEFGHIJKLMNOPQRSTUVWXY',@o varchar(max)SELECT @+='Z'+REVERSE(@)+'
',@o=@
WHILE''<@
SELECT @=STUFF(@,LEN(@)/2,2,''),@o=@+@o+@
PRINT @o

```

**Fiddle**

# Answer
> 3 votes
# 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"))

```

# Answer
> 3 votes
# 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));}

```

Try it on ideone.

# Answer
> 3 votes
# 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.

# Answer
> 3 votes
## 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**:
    + `x` is the ascii value of the next letter in the alphabet
    + `s` is an accumulator for the alphabet
    + `t` is a line in the triangle (ie `s` \+ `s backwards`)
* **Return**: `t` if the alphabet is done (ie we're at the center)
* **Else**: `t+f(...)+t` with:
    + `x` incremented
    + `s` appended with the next letter
    + `t` reset to `s` \+ `s backwards` \+ `\n`

---

**Update**

* **-2** \[16-08-05\] Remove leading `\n` (+1) and shortened conditional (-3) all thanks to *@xnor*

# Answer
> 3 votes
# 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]

```

Run it

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.

# Answer
> 3 votes
# 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.

# Answer
> 3 votes
## 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**

# Answer
> 3 votes
# 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
```

# Answer
> 3 votes
# 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.!

```

Try it online!

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

```

# Answer
> 3 votes
## brainfuck, 79 bytes

```
+<++<<--------[>+++++>>[+++<+<]>]<+[[>+>+.<<-]>-[<+>>-.<-]>->.>[->]<<<[<<++>]<]

```

Formatted:

```
+<++<<
--------[>+++++>>[+++<+<]>]
<+
[
  [>+>+.<<-]
  >-[<+> >-.<-]
  >->.>[->]
  <<<[<<++>]
  <
]

```

Try it online

# Answer
> 2 votes
# 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)

```

# Answer
> 2 votes
# bash, 80 bytes

```
printf -v a %s {A..Z};for i in {1..26} {25..1};{ echo ${a::i}`rev<<<${a::i-1}`;}

```

# Answer
> 2 votes
# ///, 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...

# Answer
> 2 votes
# Perl 5 with `-M5.010`, 54 bytes

```
for$@(A..Z){@;=($_.$/,@;);s/$*/$*$@$*/;say;$*=$@}say@;

```

Try it online!

Saved bytes thanks to @Xcali!

# Answer
> 2 votes
## 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);
};

```

# Answer
> 2 votes
# 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])-"
")

```

Try it online!

# Answer
> 2 votes
# 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.

# Answer
> 2 votes
# 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()`.

# Answer
> 2 votes
# Pepe, 94 bytes

```
rEeEeEEeEeREeEeeeeeEREEEEEEerEEReeeReeEREEEeEREEEeEREEeeREEEEEreererEEReeeReeEReReREEeEreeReee

```

Try it online!

# Answer
> 2 votes
# brainfuck, 96 bytes

```
+++++[->+++++>>++>+++++++++++++<<<<]>[->>>[.>]<[->+>+<<]>+>[-<<+>>]<<<[.<]<]>>>[[.>]<[-]<[.<]>>]

```

Try it online!

```
; 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
>>]

```

# Answer
> 2 votes
# Vyxal `j`, 8 bytes

```
kA¦ømƛøm

```

Try it Online!

Explanation:

```
kA        # Uppercase ALPHABET
  ¦       # Prefixes (A, AB, ABC, ...)
   øm     # Mirror without duplicating middle
     ƛ    # For each:
      øm  #   Mirror without duplicating middle

```

# Answer
> 1 votes
## 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ᴏʟғᴇʀ.

# Answer
> 1 votes
# 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`)
```

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
# 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

```

**Try it online**

Thanks to LeakyNun for 14 bytes off

# Answer
> 1 votes
# 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)

```

# Answer
> 1 votes
# Jelly, 16 bytes

```
ŒRAạ
25ÇÇ€‘ịØAj⁷

```

This uses the same method in my Python answer.

Try it online.

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

```

# Answer
> 1 votes
# 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);

```

# Answer
> 1 votes
# 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(""))}

```

# Answer
> 1 votes
## 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()));}}

```

Try it online!

# Answer
> 1 votes
# 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>
```

# Answer
> 1 votes
# 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.

# Answer
> 1 votes
# 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

```

# Answer
> 1 votes
# 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.

# Answer
> 1 votes
# 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.

# Answer
> 1 votes
# PHP, 78 Bytes

```
foreach(range(A,Z)as$r)$o.="\n$t".strrev($t.=$r);echo$o.substr(strrev($o),51);

```

# Answer
> 1 votes
# 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!("");
    }
}

```

# Answer
> 1 votes
## 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

```

# Answer
> 1 votes
# SOGL V0.12, 10 bytes

```
øZ{⁴Κ}¹╬,k

```

Try it Here!

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.

# Answer
> 1 votes
# Canvas, 6 bytes

```
Ｚ［│］──

```

Try it here!

Explanation:

```
Z       push the alphabet
 [ ]    map over the prefixes
  │     palindromize horizontally
    ──  palindromize vertically without mirroring characters

```

# Answer
> 1 votes
# 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".

# Answer
> 1 votes
# 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

# Answer
> 1 votes
**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.)

# Answer
> 1 votes
# 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!

# Answer
> 1 votes
# 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.

<sub>~~100 bytes~~ ~~96 bytes~~ ~~92 bytes~~ ~~80 bytes~~</sub>

# Answer
> 1 votes
# 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!

# Answer
> 1 votes
# Julia 1.0, 39 bytes

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

```

Try it online!

output is a list of strings

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
# 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))

)());
```

# Answer
> 0 votes
## Pyke, ~~19~~ 16 bytes

```
27Gm<m[D_t+)RK[X

```

Try it here!

# Answer
> 0 votes
# 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])

```

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
# 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]

```

# Answer
> 0 votes
## Convex, 21 bytes

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

```

Try it online!

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
# 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)))))

```

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
# 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 (~~88~~85 bytes)

```
for i in range(1,52):r=[*map(chr,range(65,91-abs(i-26)))];print(''.join(r+r[-2::-1]))

```

# Answer
> 0 votes
# 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.

# Answer
> 0 votes
**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);
```

# Answer
> 0 votes
## 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**

# Answer
> 0 votes
## 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")

```

# Answer
> 0 votes
## 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

```

# Answer
> 0 votes
## 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`.

# Answer
> 0 votes
# 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)))))

```

# Answer
> 0 votes
# 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

```

# Answer
> 0 votes
# 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

# Answer
> 0 votes
# 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'

```

# Answer
> 0 votes
# 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!

# Answer
> 0 votes
# 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*

# Answer
> 0 votes
# 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?

# Answer
> 0 votes
# Stax, 8 bytes

```
çtò-+è╥â

```

Run and debug it

Palindromize the palindromizations of the prefixes of the alphabet. Not very interesting program, but the challenge is back on the front page.

# Answer
> 0 votes
# Pip, 15 bytes

```
PZ(PZz@<_M\,27)

```

Try it online!

# Answer
> 0 votes
# Vyxal 3, 10 bytes

```
₂ɾṅ(nkaΘṅ,

```

Try it Online!

# Answer
> -1 votes
# Jelly, 9 bytes

```
ØAḣJŒBŒḄY

```

Try it online!

---
Tags: code-golf, kolmogorov-complexity, alphabet
---


title: Print an alphabet wave

text:
# Question
Title: Print an alphabet wave
You are to print this exact text:

```
ABABABABABABABABABABABABAB
BCBCBCBCBCBCBCBCBCBCBCBCBC
CDCDCDCDCDCDCDCDCDCDCDCDCD
DEDEDEDEDEDEDEDEDEDEDEDEDE
EFEFEFEFEFEFEFEFEFEFEFEFEF
FGFGFGFGFGFGFGFGFGFGFGFGFG
GHGHGHGHGHGHGHGHGHGHGHGHGH
HIHIHIHIHIHIHIHIHIHIHIHIHI
IJIJIJIJIJIJIJIJIJIJIJIJIJ
JKJKJKJKJKJKJKJKJKJKJKJKJK
KLKLKLKLKLKLKLKLKLKLKLKLKL
LMLMLMLMLMLMLMLMLMLMLMLMLM
MNMNMNMNMNMNMNMNMNMNMNMNMN
NONONONONONONONONONONONONO
OPOPOPOPOPOPOPOPOPOPOPOPOP
PQPQPQPQPQPQPQPQPQPQPQPQPQ
QRQRQRQRQRQRQRQRQRQRQRQRQR
RSRSRSRSRSRSRSRSRSRSRSRSRS
STSTSTSTSTSTSTSTSTSTSTSTST
TUTUTUTUTUTUTUTUTUTUTUTUTU
UVUVUVUVUVUVUVUVUVUVUVUVUV
VWVWVWVWVWVWVWVWVWVWVWVWVW
WXWXWXWXWXWXWXWXWXWXWXWXWX
XYXYXYXYXYXYXYXYXYXYXYXYXY
YZYZYZYZYZYZYZYZYZYZYZYZYZ
ZAZAZAZAZAZAZAZAZAZAZAZAZA

```

# Specs

* You can print all lowercase instead of all uppercase. However, case must be consistent throughout the output.
* You may print one extra trailing linefeed.

# Scoring

Since this is an alphabet wave that fluctuates to a small extent, your code should also be small in terms of byte-count. In fact, the smallest code in terms of byte-count wins.

# Answer
> 40 votes
# C, 60 bytes

```
main(i){for(;i<703;)putchar(i++%27?65+(i/27+i%27%2)%26:10);}

```

# Answer
> 18 votes
# Brainfuck, 104 bytes

```
>+[+[<]>>+<+]><<+++++[>+++++>>++<<<-]>[-<+++++++++++++[->>.+.-<<]>>>.<+<]<----[>+<----]>++>>+++[-<.<.>>]

```

# Answer
> 14 votes
## Convex, 10 bytes

```
U_(+]D*zN*

```

Try it online!

```
U               Predefined Variable: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 _(+            Push a copy with the 'A at the end.
    ]           Add both strings to an array.
     D*         Repeat array 13 times. D defaults to 13.
       z        Transpose.
        N*      Join by newlines. N defaults to "\n"

```

# Answer
> 9 votes
## Pyth, ~~11~~ 10 bytes

```
jC*13.<BG1

```

Try it here.

```
        G   the alphabet
       B    bifurcate over
     .<  1  left shift by 1
  *13       repeat 13 times
 C          transpose
j           join on newlines

```

# Answer
> 8 votes
# Ruby, ~~42~~ ~~39~~ ~~38~~ 37 bytes

-3 bytes thanks to @user81655
-1 byte thanks to @manatwork
-1 byte thanks to @NotthatCharles

```
?A.upto(?Z){|a|puts (a+a.next[0])*13}

```

See it on repl.it: https://repl.it/CmOJ

# Answer
> 8 votes
# Vim, ~~85~~ 83 bytes

```
:h<_<cr><cr><cr>YZZP:s/./\0\r/g<cr><c+v>ggy25Pqqlxj:let @a='xkPjj'<cr>25@akia<esc>25klq11@qh<ctrl+v>25jylpl<c+v>25jdGdd

```

I know this can be golfed more, but my head hurts so I gotta stop for now.

`<cr>` is the enter key, `<c+v>` is ctrl+v, and `<esc>` is the escape key. Those were all counted as one byte.

I recorded a gif of this, but it got screwed up. The video is fine though: http://recordit.co/ldLKvho9Gi

# Answer
> 7 votes
# Cheddar, 48 bytes

```
print(65|>90).map(l->@"[l,l>89?65:l+1]*13).vfuse

```

Cheddar is good with strings :D

Try it online!

## Explanation

```
print
  (65|>90)            // Range from 65 (A) to 90 (Z)
  .map(l->            // Map through range
    @"                // Convert following array of char codes to string
      [l,             // The character
       l>89?65:l+1]   // See below for explanation
      *13             // Repeat 13 times
  ).vfuse             // Vertically fuse

```

What does `l>89?65:l+1` do? Well `89` is the char code for `Y`. Basically, `l>89` is checking if the letter is `Z`, that means we should be returning `A`. If `l>89` is false. I'll return `l+1`, the next char

# Answer
> 7 votes
## Haskell, ~~60~~ 58 bytes

```
mapM putStrLn[[0..12]>>[a,b]|a:b:_<-scanr(:)"A"['A'..'Z']]

```

Starting with "A" `scanr(:)` builds the a list from the chars of `['A'..'Z']` from the right. (-\> `["ABCDE...A", "BCDEF..A", ..., "XYZA", "YZA", "ZA", "A"]`). `(a:b:_)` matches the first two chars of each sublists (with at least two chars) and makes 13 copies of it.

# Answer
> 7 votes
# Jelly, 10 bytes

```
26ḶḂØAṙZj⁷

```

Try it online!

### How it works

```
26ḶḂØAṙZj⁷  Main link. No arguments.

26Ḷ         Yield [0, ..., 25].
   Ḃ        Bit; compute the parity of each intger.
    ØAṙ     Rotate the alphabet by these amounts.
       Z    Zip; transpose rows and columns.
        j⁷  Join, separating by linefeeds.

```

# Answer
> 7 votes
## PowerShell, 49 43 bytes

TimmyD's remix:

```
65..89|%{-join[char[]]($_,++$_)*13};"ZA"*13

```

was, 49 bytes:

```
0..25|%{(""+[char]($_+++65)+[char]($_%26+65))*13}

```

# Answer
> 6 votes
# Python 2, ~~70~~ ~~68~~ 54 bytes

List based solution:

```
L=map(chr,range(65,91))
for i in range(-26,0):print(L[i]+L[i+1])*13

```

But why create a list? Thanks LeakyNun:

```
for i in range(26):print(chr(i+65)+chr(-~i%26+65))*13

```

# Answer
> 6 votes
# R, ~~72~~ ~~67~~ ~~60~~ 56 bytes

```
write(matrix(LETTERS[c(1:26,2:26,1)],26,26,T),"",26,,"")

```

Thanks to @Giuseppe for the extra 4 bytes off!

Old `rep`-based solution at 60 bytes:

```
for(i in 1:26)cat(rep(LETTERS[c(i,i%%26+1)],13),"\n",sep="")

```

See here on an online interpreter. Thanks to @user5957401 for the extra 7 bytes off!

Old matrix-based solution at 72 bytes:

```
for(i in 1:26)cat(matrix(LETTERS[c(1:26,2:26,1)],26,26)[i,],"\n",sep="")

```

See here on an online interpreter.

# Answer
> 6 votes
## Jellyfish, 26 bytes

```
P
+'A
~
| S
+$ r2
 ,'
r'

```

Note the trailing unprintable characters on the last two lines. Try it online!

## Explanation

This is basically an arithmetic manipulation approach: make a 26×26 grid with alternating 0-1 pattern, add the index of each row to every element of the row, reduce mod 26, and add the ASCII value of `A`. Characters in Jellyfish are just numbers with a special flag, and all arithmetic works on them as expected.

From bottom to top:

* The `'`s are character literals; they are followed by unprintables with ASCII code 26, and stand for those characters.
* The lower `r` computes the character range from 0 to 25.
* The `,` forms a pair from the two unprintable chars.
* The higher `r` is given argument `2`, and forms the range `[0 1]`.
* The `$` takes that range, and reshapes it into the shape given by its other argument, which is the pair of unprintables. This gives a 26×26 matrix of alternating rows `0 1 0 1 0 1 ...`
* The lower `+` adds the char range 0-25 to this matrix. The addition distributes on the rows, so row **i** is incremented by **i**. It's also converted to a char matrix, since the south argument consists of chars.
* The `~|` is modulus with flipped arguments: the south argument (the above char matrix) is reduced modulo the east argument (the `S` turns the argument-seeking process south, so this is the unprintable literal 26).
* The higher `+` adds the literal `A` to every coordinate of the resulting matrix.
* The `P` prints the result in matrix format, that is, each row on its own line without quotes.

# Answer
> 5 votes
## Perl, 26 bytes

*Solution from @Dom Hastings. (12 bytes shorter than mine!)*
*-1 byte thanks to @Ton Hospel*

```
say+($_++,chop)x13for A..Z

```

Run with `-M5.010` or `-E` :

```
perl -E 'say+($_++,chop)x13for A..Z'

```

# Answer
> 5 votes
# MATL, 13 bytes

```
1Y2tn:!to~!+)

```

**Try it online!**

```
1Y2    % Predefined string literal: 'AB···Z'
tn:    % Duplicate, number of elements, range: gives [1, 2, ···, 26]
!      % Transpose into a column vector
to~!   % Duplicate and transform into [0, 1, 0, 1, ···, 1] using modulo 2
+      % Addition with broadcast. Gives 2D numeric array
)      % Index (modularly) into string. Implicitly display.

```

# Answer
> 5 votes
**T-SQL 133 Bytes** (Golfed by : @t-clausen.dk)

```
SELECT REPLICATE(Char(number+65)+IIF(number=25,'A',Char(number+66)),13)FROM spt_values WHERE number<26and'P'=TYPE

```

**T-SQL , 151 Bytes**

Using CTE to generate sequence of number

```
;WITH n(a,v) AS(SELECT CHAR(65)+CHAR(66), 66 UNION ALL SELECT CHAR(v)+CHAR(v+1), v+1 FROM n WHERE v < 91)SELECT REPLICATE(REPLACE(a,'[','A'),13) FROM n

```

**T-SQL, 155 Bytes**

```
SELECT REPLICATE(Char(number+65)+ CASE WHEN number=25 THEN 'A' ELSE Char(number+66) END, 13) FROM master.dbo.spt_values  WHERE name IS NULL AND number < 26

```

# Answer
> 5 votes
# Vim, 31 bytes

```
:h<_↵↵↵YZZPJra0qqy2l13Plr↵25@qD

```

Where  is the Return key.

# Answer
> 4 votes
# Julia, 46 bytes

```
[println("$c$(c+1-26(c>89))"^13)for c='A':'Z']

```

Try it online!

# Answer
> 4 votes
# Pyth, 10 bytes

```
jCm.<G~!ZG

```

Demonstration

Explanation:

```
jCm.<G~!ZG
  m      G    Map over G, predefined to the lowercase alphabet.
              This will give 26 columns.
   .<G        Left shift (cyclically) G by
        Z     Z elements. Z is initialized to 0.
      ~!      After using its value, logical not Z. (0 -> 1, 1 -> 0)
 C            Transpose
j             Join on newlines

```

# Answer
> 4 votes
## Brainfuck, ~~88~~ 86 bytes

```
++[[+>]<+<++]+>-[[->+>+<<]>>-]++++++++[<[++++++++<+<]>[>]<-]<<++<[>+++[->.<<.>]<<++.<]

```

Requires an interpreter with 8-bit cells and a tape not bounded on the left. Try it online!

# Answer
> 3 votes
# Lua, 80 65 Bytes.

```
s = string c = s.char for i=1,26 do print(s.rep(c(64+i)..c((65+(i%26))),13)) end

```

With help from Leaky Nun

```
c=("").char for i=1,26 do print((c(64+i)..c(65+i%26)):rep(13))end

```

Lua is a pretty inefficent language in regards to handling of strings and such, so this is the best I can narrow it down.

# Answer
> 3 votes
# Brachylog v1, ~~30~~ ~~24~~ 20 bytes

```
~~@Ab:"a"c:@Arz:{:12jc:@Nc.}a:wa~~
~~@Ab:"a"c:@Arze:12jcw@Nw\~~
@A$(:@Arze:12jcw@Nw\

```

Try it online!

# Answer
> 3 votes
## 05AB1E, 12 bytes

```
ADÀ)øvyJ5Ø×,

```

**Explanation**

```
AD            # push 2 copies of the alphabet
  À           # rotate the 2nd one left by 1
   )ø         # add to list and zip
     v        # for each
      yJ      # join the pair
        5Ø×   # repeat it 13 times
           ,  # print with newline

```

Try it online

# Answer
> 3 votes
# TSQL, 111 bytes

```
DECLARE @o varchar(702)='',@ int=1WHILE @<702SELECT @o+=CHAR(IIF(@%27=0,10,65+(@/27+1-@%27%2)%26)),@+=1PRINT @o

```

Fiddle

# Answer
> 3 votes
# Mathematica, ~~82~~ ~~75~~ ~~67~~ 66 bytes

```
Print@FromCharacterCode@PadLeft[{},26,{i-1,i}~Mod~26+65]~Do~{i,26}

```

Technically shorter, although it prints in lowercase instead of uppercase:

# Mathematica, 64 bytes

```
Print[""<>FromLetterNumber@Table[{i-1,i}~Mod~26+1,13]]~Do~{i,26}

```

# Answer
> 3 votes
# APL (Dyalog Unicode), 12 bytes

```
⍉↑26⍴⌽∘⎕A¨⍳2

```

Try it online!

Requires `⎕IO←0`, so that `⍳2` evaluates to `0 1`.

### How it works

```
⍳2     ⍝ 0 1
⌽∘⎕A¨  ⍝ Rotate the uppercase alphabet 0 and 1 times,
       ⍝ giving ["ABC..Z", "BCD..ZA"]
26⍴    ⍝ Cycle the two strings to the length of 26
⍉↑     ⍝ Promote to a matrix and transpose

```

---

## Bunch of 13- and 14-byte solutions

```
⍉↑26⍴⎕A(1⌽⎕A)
⍉↑26⍴0 1⌽¨⊂⎕A
(26⍴⍳2)⊖∘.⊣⍨⎕A
∪⍉↑26⍴↓2 27⍴⎕A
∪26⍴⍤1⍉2 27⍴⎕A

```

These are included in the TIO link above.

# Answer
> 2 votes
# J, ~~20~~ 19 bytes

**1 byte thanks to miles.**

```
u:65+26|(+/2&|)i.26

```

Online interpreter

This is actually the program I used to generate the text in the challenge.

# Answer
> 2 votes
# Oracle SQL 11.2, ~~141~~ 138 bytes

```
SELECT LISTAGG(CHR(l+64)||CHR(MOD(l,26)+65))WITHIN GROUP(ORDER BY l)FROM(SELECT CEIL(LEVEL/13)l FROM DUAL CONNECT BY LEVEL<339)GROUP BY l;

```

Un-golfed

```
SELECT LISTAGG(CHR(l+64)||CHR(MOD(l,26)+65))WITHIN GROUP(ORDER BY l)
FROM   (
         SELECT CEIL(LEVEL/13)l
         FROM   DUAL
         CONNECT BY LEVEL<339  -- 26*13+1
       )
GROUP BY l

```

# Answer
> 2 votes
# T-SQL 99 90 bytes

Saved 9 bytes thanks to @t-clausen.dk

`DECLARE @ INT=65z:PRINT REPLICATE(CHAR(@)+CHAR(IIF(@=90,65,@+1)),13)SET @+=1IF @<=90GOTO z`

Ungolfed:

```
DECLARE @CurrCharacter INT = 65; --ASCII decimal for 'A'
WHILE (@CurrCharacter <=90) --ASCII decimal for 'Z'
BEGIN
   PRINT REPLICATE(
    REPLACE(CHAR(@CurrCharacter)+CHAR(@CurrCharacter+1),'[','A')
    ,13); --Replicate the current character and its neighbor 13 times. If the neighbor is '[' (ASCII code 91) then replace it with 'A'.
   SET @CurrCharacter+=1; --Go to the next letter
END

```

# Answer
> 2 votes
# 05AB1E, ~~11~~ 9 bytes

```
AuDÀø13×»

```

Try it online!

Posting because it beats the other 05AB1E answer and kinda uses a different method

*-2 with vectorisation*

## Explained

```
Au          # Push the uppercase alphabet. STACK = [A-Z]
  D         # Duplicate that. STACK = [A-Z, A-Z]
   À        # Rotate the alphabet left. STACK = [A-Z, Rotate_Left(A-Z)]
    ø       # Zip those two alphabets. STACK = ["AB", "BC", "CD", "DE", "EF", "FG", "GH", "HI", "IJ", "JK", "KL", "LM", "MN", "NO", "OP", "PQ", "QR", "RS", "ST", "TU", "UV", "VW", "WX", "XY", "YZ", "ZA"]
     13×»   # Repeat each 13 times and join with newline

```

# Answer
> 2 votes
# jq `-nr`, 41 bytes

```
range(26)|[(.+range(26)%2)%26+65]|implode

```

Try it online!

# Answer
> 1 votes
## JavaScript (ES6), ~~88~~ 83 bytes

```
_=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"].map((c,i,a)=>(c+a[-~i%26]).repeat(13)).join`\n`

```

Where `\n` represents the literal newline character. Writing the alphabet out saved me three bytes today, but @LeakyNun saved me another five bytes.

# Answer
> 1 votes
**MATLAB, ~~47~~ 38 bytes**

```
a=(65:90)';char(repmat([a a([2:end 1])],1,13))

char(repmat([65:90;[66:90 65]]',1,13))

```

The first makes a column array of the alphabet in ASCII, appends a shifted copy as a column to its right, replicates the resulting 26\*2 array 13 times columnwise, casts to a character array and prints by default.

The second makes a 2\*26 array of alphabet and shifted alphabet, transposes it then continues as above.

# Answer
> 1 votes
## Neoscript, 59 bytes

```
a=('A:[]:'Z)+'Aeach n=0:[]:25console:log((a[n]+a[n+1])*13);

```

# Answer
> 1 votes
# Javascript (using external library Enumerable) (84 bytes)

```
    n=>(w=_.Range(0,26)).WriteLine(x=>w.Write("",y=>String.fromCharCode((x+y%2)%26+65)))

```

Link to lib: https://github.com/mvegh1/Enumerable/

Code explanation: Create a range of ints starting at 0 for count of 26. Store into global variable w. For each, write a new line according to predicate. Predicate states to take "w" and write a joined string based off the passed predicate to Write. Predicate to Write uses an empty string as the join delimiter, and uses the current integer value from WriteLine ("x") and the current integer value from Write ("y") to calculate the correct string at that position

Edit: Removed extra parens to save 2 bytes

# Answer
> 1 votes
# PHP, 102 bytes

```
<?php $a='ABCDEFGHIJKLMNOPQRSTUVWXYZA';$i=-1;while($i++<25){echo str_repeat(substr($a,$i,2),13)."\n";}

```

# Answer
> 1 votes
# Ruby, 41 bytes

```
26.times{|i|puts [*?A..?Z,?A][i,2]*''*13}

```

# Answer
> 1 votes
# **C (86 bytes):**

```
for(int c=-11,n=-26;++n<1;){while(c++){printf("%c%c",90+n,n?91+n:65);}c=-11;puts("");}

```

My first attempt on a Code Golf challenge.

Some answers are really impressive!

# Answer
> 1 votes
# PHP, 65 bytes

Well, this is pretty straight forward:

```
for(;$i<26;)echo str_repeat(chr(65+$i).chr(65+(++$i%26)),13)."
";

```

# Answer
> 1 votes
# C#, 107 bytes

My first attempt at a submission to PPCG

Golfed:

```
var l="";int i=0,j=0;for(;i<26;i++){for(;j<26;j++)l+=(char)(((j%2)+i)%26+65);Console.WriteLine(l);l="";j=0;}

```

Ungolfed:

```
var l="";
int i=0,j=0;
for(;i<26;i++){
    for(;j<26;j++)l+=(char)(((j%2)+i)%26+65);
        Console.WriteLine(l);
    l="";j=0;
}

```

Pretty sure this adheres to standards! Would love to hear any potential improvements.

# Answer
> 1 votes
# Java 7, 87 bytes

```
void c(){for(int i=0;i<703;)System.out.print((char)(i++%27>0?65+(i/27+i%27%2)%26:10));}

```

Based on *@orlp*'s amazing answer.

**Ungolfed & test code:**

Try it here.

```
class Main {
  public static void main(String[]a){
    c();
  }

  static void c(){
    for(int i=0; i<703;){
        System.out.print((char)(i++%27 > 0
                                  ? 65 + (i/27+i%27%2)%26
                                  :10));
    }
  }
}

```

# Answer
> 1 votes
# Python 2 53 bytes

```
i=0;exec'print(chr(i+65)+chr(-~i%26+65))*13;i+=1;'*26

```

# Answer
> 1 votes
# Common Lisp, SBCL, 86 bytes

```
(dotimes(i 26)(format t"~13@{~a~:*~}~%"(subseq"ABCDEFGHIJKLMNOPQRSTUVWXYZA"i(+ i 2))))

```

### Explanation

```
(dotimes(i 26);loop from i=0 to i=25
(format t"~13@{~a~:*~}~%"(subseq"ABCDEFGHIJKLMNOPQRSTUVWXYZA"i(+ i 2))))
;print 13 times pairs of "AB", "BC", ... , "ZA"

```

# Answer
> 1 votes
### c64 basic v2, 95 93 85 83 77 bytes

```
0fOy=65to90:l$="":a$=cH(y)+cH(y+1+(y=90)*26)
1fOx=0to12:l$=l$+a$:nE:?l$:nE

```

Screenshot:

Trial instructions are in my previous answer.

# Answer
> 1 votes
# SOGL V0.12, 8 bytes

```
Z«Z¹'⁰∙I

```

Try it Here!

Explanation:

```
Z         push the uppercase alphabet
 «        put its first letter at the end
  Z       push the alphabet once again
   ¹      wrap in array: ["BCDEFGHIJKLMNOPQRSTUVWXYZA", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
    '⁰∙   multiply vertically 13 times
       I  rotate clockwise

```

# Answer
> 1 votes
# Bash, 64 bytes

```
f()(tr A-Z B-ZA|tee >(((i++<25))&&f);echo)
printf ZA%.s {a..m}|f

```

Credit to seshoumara's `sed` answer for the idea of translating `A-Z` to `B-ZA`.

Try it online!

# Answer
> 1 votes
# Visual Basic .NET (Mono), 140 bytes

```
Module M
Sub Main
Dim I,J,S
For I=1To 26
S=""
For J=0To 11
S+=Chr$(I+64)+Chr$(I Mod 26+65)
Next
Console.WriteLine(S)
Next
End Sub
End Module

```

Try it online!

# Answer
> 1 votes
# MY-BASIC, 77 bytes

```
For I=1 To 26
For J=0 To 12
Print Chr(I+64)+Chr(I Mod 26+65)
Next
Print;
Next

```

Try it online!

# Answer
> 1 votes
# PHP, ~~78, 72,~~ 67 bytes

```
<?php $s='A';while($s!='AA')echo str_repeat($s++.(--$s)[0],13)."
";

```

Try it online!

# Answer
> 1 votes
# APL (Dyalog Unicode), 13 bytesSBCS

```
⍉(⎕a⌽⍨2|⊢)⌸⎕a
```

Try it online!

# Answer
> 1 votes
# Charcoal, 15 bytes

```
Ｅ²⁶⎇﹪ι²α⁺ΦαμA⟲⁶

```

Link is to verbose version of code.

Try it online!

# Answer
> 1 votes
# Knight, 34 bytes

```
;=a 65;W>90aO*+AaA=a+1a 13O*"ZA"13

```

Try it online!

Expanded code:

```
;=a 65
;WHILE > 90 a
  OUTPUT * (+(ASCII a) (ASCII (= a(+ 1 a)))) 13
OUTPUT (* "ZA" 13)

```

There's probably a better way to deal with the last row, but I don't know it.

Another 34-byte solution:

```
;=a 0W>26aO*+A+65aA+65%=a+1a 26 13

```

# Answer
> 0 votes
# Julia, 51 bytes

```
!()=join(["$x$(x+1-26(x>89))"^13for x='A':'Z'],"
")

```

Initial golfing.

# Answer
> 0 votes
# C, ~~77~~ ~~74~~ 71 bytes

Basically the same as the Python answer inspired by LeakyNun, Thanks to owacoder for `puts` :

```
f(i,j){for(i=0;++i<27;puts(""))for(j=13;--j;printf("%c%c",i+64,i%26+65));}

```

Usage:

```
f();

```

~~While mathematically `(26-n)%26 == (-n)%26`, this is not true for C, otherwise these two bytes can be shaved off.~~ Using a count up loop for `i` resolves the problem

# Answer
> 0 votes
# Java 8, ~~139~~ 137 bytes

```
()->{for(int i=65,j=1;;j++){if(j>25){j=++i<91?1:0;System.out.println();
if(j==0)break;}System.out.print((char)i+""+(char)(i>89?65:i+1));}}

```

# Answer
> 0 votes
## Javascript(ES5), 107 99 bytes

```
for(var s="",i=-1;++i<676;)i&&!(i%26)&&(s+="\n"),s+=String.fromCharCode((i/26+i%2)%26+65);alert(s);

```

# Answer
> 0 votes
# RETURN, 23 bytes

```
'A'[␊'B'[␊'A␈13␋␄'␊°␇␂,

```

`Try it here.`

NOTE: Use the "Insert String" button and paste the above code in.

# Explanation

Basically generates `A-Z` and `B-Z and A at the end` on the stack. Then the stack is duplicated 13 times, transposed, joined with a newline, and outputted.

Due to a bug that I just can't fix, `'A'[␊${25@}13␋␄'␊°␇␂,` does not work.

# Answer
> 0 votes
# C# - 159 138 bytes

```
var a="ABCDEFGHIJKLMNOPQRSTUVWXYZA";for(int i=0;i<26;i++){for(int j=0;j<14;j++){Console.Write("{0}{1}",a[i],a[i+1]);}Console.WriteLine();}

```

# Answer
> 0 votes
# JAVA 9, ~~103~~ 97 bytes

it works on JShell, provided by Java9 SDK.

```
for(int c=64,i;++c<91;)for(i=0;i<26;)System.out.print((char)((c-13+i%2)%26+65)+(i++<25?"":"\n"))

```

# Answer
> 0 votes
## Pyke, 13 bytes

```
GGt\a+]w-*,_X

```

Try it here!

# Answer
> 0 votes
## ListSharp, 236 bytes

```
ROWS x=ROWSPLIT "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,T,S,U,V,W,X,Y,Z,A" BY [","]
[FOREACH NUMB IN 1 TO 26 AS i]
{
STRG t =""
[FOREACH NUMB IN 1 TO 13 AS j]
{
STRG e=GETLINE x [i]
STRG r=GETLINE x [i+1]
STRG t=t+e+r
}
ROWS s=s+t
}
SHOW=s

```

Feel free to comment if you want anything to be explained to you

Execution screenshot:

# Answer
> 0 votes
# Perl 6, 50 bytes

```
say .join x 13 for flat('A'..'Z','A').rotor(2=>-1)

```

# Answer
> 0 votes
# EXCEL: 53 bytes

```
=REPT(CHAR(ROW(A1)+64)&CHAR(MOD(ROW(A1),26)+65),13)

```

Place in A1 and drag to desired length of wave (in this case, 26, one cell for each letter).

# Answer
> 0 votes
Improving on @gabe3886's answer (new account and not able to comment)

## PHP 94 92 Bytes

```
<?php for($i=0;$i<26;)echo str_repeat(substr('ABCDEFGHIJKLMNOPQRSTUVWXYZA',$i++,2),13)."\n";

```

However if you suppress notices, it's 92 90 bytes

```
<?php for(;@$i<26;)echo str_repeat(substr('ABCDEFGHIJKLMNOPQRSTUVWXYZA',@$i++,2),13)."\n";

```

# Answer
> 0 votes
# Logo, 93 bytes

Here's a non-graphical Logo solution. Try it online with Calormen.com's interpreter.

```
to m:c type char 65+modulo:c 26end
to b:a repeat 13[m:a-1 m:a] pr" end
repeat 26[b repcount]

```

# Answer
> 0 votes
# JavaScript, Z (90) bytes

```
for(i=65,b=66;i<91;++i,b=b<90?++b:65)console.log(Array(14).join(String.fromCharCode(i,b)))

```

*To learn*:

```
var start = 65,
    end = 90;

for (var i = start, b = i+1; i <= end; ++i) {
    var chars = String.fromCharCode(i, b);
    /* repeat chars 14 times */
    console.log(Array(14).join(chars));
}

```

# Answer
> 0 votes
**VIM, 42**

```
:h<_↵↵↵YZZP:s/./&\r/g↵^25↑y↑pG2↑aa↓^ggy13P

```

where:

* is return,
* ^ is ctrl + v
* ↑ is the up arrow
* ↓ is escape

I'm sure this can be golfed more. I'm new to VIM so any suggestions are appreciated.

# Answer
> 0 votes
**python 3, ~~92~~ 90 bytes**

```
a=65
b=66
for i in range(312):
    if a>89:b=65
    print(chr(a)+chr(b),end="")
    if (i+1)%12<1:
        a+=1
        b+=1
        print()

```

**python 2, 80 bytes**

```
a=65
b=66
for i in range(312):
    if a>89:b=65
    print chr(a)+chr(b),
    if (i+1)%12<1:
        a+=1
        b+=1
        print

```

This program outputs `AB AB AB AB...` rather than `ABABABAB...` I'm not sure if this is allowed, but it's the best I can come up with.

**EDIT:**

Thanks @User902383 for you comment on @TAsk's post allowing me to shave off 2 bytes.

And thanks @NoOneIsHere for suggesting that I move to python 2 instead of 3, I've included a second program in python 2 with a new byte count.

# Answer
> 0 votes
# Scala, 64 bytes

Can anyone improve on this?

```
(('A'to'Z'):+'A').sliding(2).map(_.mkString*13).foreach(println)

```

# Answer
> 0 votes
# Python 2.7, 65 bytes

Python 2 alternative using a recursive function

```
def l(a=0):
 print(chr(a+65)+chr(-~a%26+65))*13
 if a<25:l(-~a)

```

# Answer
> 0 votes
# Vitsy, 29 bytes

So, instead of doing the typical thing, I used my two-dimensional stacking to generate the alphabets and then offset them by one from each other, alternating back and forth between them.

```
9a*d5*Hd\[:{:}]Y?y\[y\[O?]aO]

9a*d5*H                        Push an alphabet to the stack.
9a*                                 Push 90 to the stack (character code 'Z')
   d5*                              Push 65 to the stack (character code 'A')
      H                             Pop a, b, push range (a, b)

       d\[:{:}]                Establish the other stacks, while alternating.
       d\[    ]                     Do the bracketed code 13 times.
          : :                       Clone the stack.
           {                        Put the top item of the stack on the bottom.
             }                      Put the bottom item of the stack on the top.
               Y                    Discard a stack. (13*2+1-1 = 26)
                ?                   Rotate right a stack (we start on 'A' now)
                 y\[y\[O?]aO]  Output.
                 y\[        ]       Repeat the code in brackets number of stacks times (26).
                    y\[  ]          Repeat the code in brackets number of stack times (26).
                       O            Pop a, print a as a character.
                        ?           Go right a stack.
                          aO        Output a newline.

```

Try it online!

# Answer
> 0 votes
## PHP, 70 66 64 Bytes

```
<?$a=A;$b=B;while($a!=AA)echo str_repeat($a++.($b++)[0],13)."
";

```

3 bytes short (if I would remove the `<?` as well) from @insertusernamehere answer. So close!

EDIT: Actually got it to 66 bytes (64 without the `<?`)! Doing A and B without quotes actually seem to work. Seems to be the shortest PHP one as time of write :D

EDIT 2: Also removed " " from AA. Still seems to be working.

# Answer
> 0 votes
# Bash, 149, 115, ~~111~~, 106 bytes

```
for i in {0..25};{
printf $(printf %b%b \\`printf %o $[i+65]` \\`printf %o $[-~i%26+65]`)%.s {a..m};echo
}

```

(thanks @manatwork, saved 34, 4 more bytes)

# Bash, 140 bytes

(thanks @steeldriver)

```
for i in {0..25}; do printf "$(printf '%b%b' \\$(printf '%03o' $((i+65))) \\$(printf '%03o' $((-~i%26+65))))%.0s" {1..13}; printf \\n; done

```

Save to `<file>` and run as: `/bin/bash <file>`

# Answer
> 0 votes
## GNU sed, 95 bytes

```
s,^,@@@@@@@@@@@@@,;s,@,AB,g
:;p
y,ABCDEFGHIJKLMNOPQRSTUVWXYZ,BCDEFGHIJKLMNOPQRSTUVWXYZA,
/^Z/!b

```

I wish the 'y' command had this syntax: `y,A-Z,B-ZA,`.

# Answer
> 0 votes
# Python, 56

```
for k in range(26):print(chr(k+65)+chr((k+1)%26+65))*13

```

# Answer
> 0 votes
# PHP, 52 bytes

```
for($a=A;$a!=AA;)echo str_pad("\n",27,$a++.$a[0],0);

```

Can JavaScript beat this? Run with `-r`.

# Answer
> 0 votes
# Javascript, 98 Bytes

```
for(var j=371,s="";j<1333;j+=37){for(i=0;i<13;i++)s+=j.toString(36).replace("100","za");s+="<br>"}

```

Try it here

# Answer
> 0 votes
# tcl, 80

```
time {puts [string repe [format %c%c [expr [incr i]+64] [expr $i%26+65]] 13]} 26

```

## demo

---

~~tcl, 86
```
while {[incr i]<27} {puts [string repe [format %c%c [expr $i+64] [expr $i%26+65]] 13]}

```
demo
~~

# Answer
> 0 votes
# Bash \+ Unix utilities, ~~53~~ 52 bytes

```
dc "-e65[d257*1+16 52^65535/*POP1+d91>x]dsxx"|tr [ A

```

Try it online!

Test run:

```
dc "-e65[d257*1+16 52^65535/*POP1+d91>x]dsxx"|tr [ A
ABABABABABABABABABABABABAB
BCBCBCBCBCBCBCBCBCBCBCBCBC
CDCDCDCDCDCDCDCDCDCDCDCDCD
DEDEDEDEDEDEDEDEDEDEDEDEDE
EFEFEFEFEFEFEFEFEFEFEFEFEF
FGFGFGFGFGFGFGFGFGFGFGFGFG
GHGHGHGHGHGHGHGHGHGHGHGHGH
HIHIHIHIHIHIHIHIHIHIHIHIHI
IJIJIJIJIJIJIJIJIJIJIJIJIJ
JKJKJKJKJKJKJKJKJKJKJKJKJK
KLKLKLKLKLKLKLKLKLKLKLKLKL
LMLMLMLMLMLMLMLMLMLMLMLMLM
MNMNMNMNMNMNMNMNMNMNMNMNMN
NONONONONONONONONONONONONO
OPOPOPOPOPOPOPOPOPOPOPOPOP
PQPQPQPQPQPQPQPQPQPQPQPQPQ
QRQRQRQRQRQRQRQRQRQRQRQRQR
RSRSRSRSRSRSRSRSRSRSRSRSRS
STSTSTSTSTSTSTSTSTSTSTSTST
TUTUTUTUTUTUTUTUTUTUTUTUTU
UVUVUVUVUVUVUVUVUVUVUVUVUV
VWVWVWVWVWVWVWVWVWVWVWVWVW
WXWXWXWXWXWXWXWXWXWXWXWXWX
XYXYXYXYXYXYXYXYXYXYXYXYXY
YZYZYZYZYZYZYZYZYZYZYZYZYZ
ZAZAZAZAZAZAZAZAZAZAZAZAZA

```

# Answer
> 0 votes
# Windows batch, 155 bytes

```
@set s=ABCDEFGHIJKLMNOPQRSTUVWXYZA
@set/ac=-1
:L
@set/ac+=1
@call set t=%%s:~%c%,2%%
@for /l %%i in (1,1,13) do @cd|set/p=%t%
@echo(
@if %t% neq ZA @goto l

```

# Answer
> 0 votes
# Excel VBA, 50 Bytes

Anonymous VBE immediate window function that takes no input and outputs a wave to the range `[A1:Z26]` on the ActiveSheet object

```
[A1:Z26]="=Char(Mod(Row()+IsEven(Column()),26)+64)

```

# Answer
> 0 votes
# Recursiva, 19 bytes

```
{B26'P*13Z~}+(C65;}

```

Try it online!

# Answer
> 0 votes
# Pyth, 12 bytes

I haven't been there

```
VG*13+N@G=hZ

```

Explanation:

```
VG       In the lowercase alphabet...
  *13     13 times...
  +N@G=hZ The current item concatenated with alphabet[++Z]

```

Try it online!

# Answer
> 0 votes
# K (oK), 23 bytes

**Solution:**

```
`c$65+26#'a,'1_27#a:!26

```

Try it online!

**Explanation:**

```
`c$65+26#'a,'1_27#a:!26 / solution
                    !26 / range 0..25
                  a:    / save as 'a'
               27#      / 27 take, wraps to make ABC...XYZA
             1_         / 1 drop, take off leading A
          a,'           / concatenate each element with each of a (AB,BC,etc)
      26#'              / 26 take each, wraps to get ABABAB... BCBCBC... etc
   65+                  / add 65, vectorised (65=A in ASCII)
`c$                     / cast to characters

```

**Bonus:**

Here are a couple of other ways to get the result:

**24 chars:** Try it online!

```
`c$65++26#(!26;1_27#!26)

```

**27 chars:** Try it online!

```
26#'+0 1_'26 27#\:`c$65+!26

```

# Answer
> 0 votes
# q/kdb+, 19 bytes

**Solution:**

```
26#'.Q.A,'1_27#.Q.A

```

**Explanation:**

Shorter and different to my `oK` solutions as we have a shortcut to the uppercase alphabet by means of `.Q.A`. As always, interpreted right-to-left

```
26#'.Q.A,'1_27#.Q.A / solution
               .Q.A / shortcut to uppercase alphabet, ABC..XYZ
            27#     / 27 take, wraps to get ABC...XYZA
          1_        / 1 drop, drop first element to give BCD...XYZA
    .Q.A,'          / concatenate each left/right lists, so AB, BC, CD etc
26#'                / 26 take each, gives ABABA.. BCBCB... etc

```

# Answer
> 0 votes
# Mathematica, 52 bytes

```
Column[""<>#~Table~13&/@Partition[Alphabet[],2,1,1]]

```

-1 byte from Martin Ender

# Answer
> 0 votes
# Yabasic, 69 bytes

```
For I=1To 26
For J=0To 12
?Chr$(I+64)+Chr$(Mod(I,26)+65);
Next
?
Next

```

Try it online!

# Answer
> 0 votes
# uBASIC, 83 bytes

```
0ForI=1To26:ForJ=0To12:?Left$(Chr$(I+64),1)+Left$(Chr$(IMod26+65),1);:NextJ:?:NextI

```

Try it online!

# Answer
> 0 votes
# Pip `-n`, 18 bytes

```
(z.z)@>_@<2X13M,26

```

Pip doesn't have transpose, so I just took two letter substrings and repeated them.

`-n` joins lists with newlines.

Try it online!

# Answer
> 0 votes
# Jelly, 10 bytes

```
ØA,Ɲẋ€13j⁷

```

Try it online!

Noncompeting probably because some of the atoms are new.

# Answer
> 0 votes
# Vyxal `j`, 10 bytes

```
kA:ǓZv∑13*

```

Try it Online!

```
kA         # Uppercase alphabet
  :ǓZ      # Zip with a copy  rotated one to the left
     v∑    # Sum each
       13* # Repeat each 13x

```

# Answer
> 0 votes
# Japt `-R`, 11 bytes

```
;B¬£BéÓYvÃy

```

Test it

# Answer
> 0 votes
# Python 2, 78 bytes

```
a="abcdefghijklmnopqrstuvwxyz"
for i in range(len(a)):print(a[i]+a[-~i%26])*13

```

Try it online!

# Answer
> 0 votes
# Zsh, 46 bytes

```
p=A
for c ({B..Z} A)<<<${(el:52::$p$c:)}&&p=$c
```

Attempt This Online!

# Answer
> 0 votes
# Vyxal 3 `j`, 8 bytes

```
mmṘZṠ13×

```

Try it Online!

---
Tags: code-golf, kolmogorov-complexity, alphabet
---


title: How many laps around the permutation?

text:
# Question
Title: How many laps around the permutation?
Your input is an array of numbers: a permutation of \\$\\{1, 2 \dots n\\}\\$ for some integer \\$n \geq 2\\$.

How many times must you repeat this list before you can "pick out" the numbers \\$\[1, 2 \dots n\]\\$ in order?

That is: find the lowest \\$t \geq 1\\$ so that \\$\[1, 2 \dots n\]\\$ is a subsequence of \\$\text{repeat}(\text{input}, t)\\$.

This is : write the shortest program or function that accepts a list of numbers and produces \\$t\\$.

## Example

For `[6,1,2,3,5,4]`, the answer is `3`:

```
6,1,2,3,5,4    6,1,2,3,5,4    6,1,2,3,5,4
  ^ ^ ^   ^            ^      ^

```

## Test cases

```
[2,1] -> 2
[3,2,1] -> 3
[1,2,3,4] -> 1
[4,1,5,2,3] -> 2
[6,1,2,3,5,4] -> 3
[3,1,2,5,4,7,6] -> 4
[7,1,8,3,5,6,4,2] -> 4
[8,4,3,1,9,6,7,5,2] -> 5
[8,2,10,1,3,4,6,7,5,9] -> 5
[8,6,1,11,10,2,7,9,5,4,3] -> 7
[10,5,1,6,11,9,2,3,4,12,8,7] -> 5
[2,3,8,7,6,9,4,5,11,1,12,13,10] -> 6

```

# Answer
> 11 votes
# Jelly, 5 bytes

```
Ụ>ƝS‘

```

Try it online!

```
Ụ     -- Grade up. Indices that would sort the input
 >Ɲ   -- For each pair of adjacent values, is the left larger than the right?
   S  -- Sum the boolean results
    ‘ -- Increment by 1

```

# Answer
> 10 votes
# Python 3, 36 bytes

```
f=lambda x,*p:p==()or(x-1in p)+f(*p)

```

Try it online!

The number of repeats needed is equal to the number of pairs `x` and `x+1` such that the `x+1` appears before `x` in the permutation, plus one.

# Answer
> 8 votes
# Julia 1.0, 30 bytes

```
a->sum(diff(sortperm(a)).<0)+1

```

Try it online!

-2 bytes thanks to @dingledooper.

# Answer
> 4 votes
# Vyxal, 6 bytes

```
⇧¯0<∑›

```

Try it Online!

Port of ovs's jelly answer.

```
⇧      # Grade up
 ¯0<   # Cumulative differences less than 0
    ∑› # Sum + 1

```

# Answer
> 3 votes
# , 34 bytes

```
function(l)sum(diff(order(l))<0)+1

```

Try it online!

Port of e.g., Sundar R's answer.

# , ~~77~~ ~~69~~ 67 bytes

```
function(l){while(all(combn(rep(l,T),max(l),is.unsorted)))T=T+1
+T}

```

Try it online!

Brute force: `combn(rep(input,t),max(input))` generates all `length(input)` subsequences of \\$\text {repeat}(\text {input},t)\\$, and check for one that is sorted.

-2 bytes thanks to pajonk.

# Answer
> 3 votes
# Wolfram Language (Mathematica), ~~33~~ ~~31~~ 30 bytes

-1 thanks to alephalpha

```
Count[#-##2&@@@#~Subsets~2,1]&

```

Try it online!

Input `[list]`.

Doesn't work for \\$n=1\\$, but we're guaranteed \\$n\ge 2\\$.

---

### Wolfram Language (Mathematica), ~~37~~ 36 bytes

```
Tr@Boole[Set@a;Set[a,#,a]!=#-1&/@#]&

```

Try it online!

The number of repeats is also equal to the number of prefixes `...,x` that don't contain `x-1`.

```
         Set@a;                     clear prefix
                              &/@#  for each:
                           #-1        predecessor
               Set[a,#,a]!=           not in prefix
Tr@Boole[                         ] count

```

# Answer
> 3 votes
# Haskell, ~~39~~ 34 bytes

*Thanks @Unrelated String for -3 bytes*

*Thanks @Bubbler for another -2 bytes*

```
f[]=1
f(h:t)=sum[1|elem(h-1)t]+f t

```

Try it online!

Port of @dingledooper's Python answer

Answered as part of the current Haskell LYAL event. Tell me if there are any golfs, this is my first time coding in Haskell.

# Answer
> 2 votes
# Factor, 42 bytes

```
[ arg-sort differences [ 0 < ] count 1 + ]

```

Port of @SundarR's Julia answer.

## Explanation

Arg-sort the input (i.e. get the indices that sort the input), get their first-order differences, count how many elements are negative, and add one.

```
               ! { 6 1 2 3 5 4 }
arg-sort       ! { 1 2 3 5 4 0 }
differences    ! { 1 1 2 -1 -4 }
[ 0 < ] count  ! 2
1              ! 2 1
+              ! 3

```

Try it online!

# Answer
> 2 votes
# MATL, ~~11~~ ~~8~~ 7 bytes

```
&Sd0<sQ

```

Try it online!

Straight port of my Julia answer (using the second output of `sort` in place of `sortperm` \- thanks to @Giuseppe for that idea, saving me 3 bytes).

Another -1 byte thanks to @LuisMendo (so rusty with MATL I forgot `&` even existed!)

# Answer
> 2 votes
# Octave, 24 bytes

```
@(a)nnz(tril(a==a'+1))+1

```

Try it online!

Port of @dingledooper's Python 3 answer.

# Answer
> 2 votes
# APL(Dyalog Unicode), ~~49~~38 bytes SBCS

```
{0=⌈/⍵:1⋄~1∊⍺:1+⍵∇⍵⋄(⍵-1)∇⍨¯1+⍺↓⍨⍺⍳1}⍨

```

Try it on APLgolf!

A dfn submission which uses recursion (yuck) to keep track of things. Instead of looking for increasing numbers, we decrement the sequence and always look for a `1`: this means that, as we recurse, we don't need to keep track of the number we are searching for.

contains the tail of the sequence where we can still look for 1s, and  contains a copy of the original sequence, but decremented by the amount of times we already found the next digit.

Then, we just look for the next number in the sequence tail.

* If it's there, chop the sequence tail and call the function recursively, after decrementing the original sequence again and the new tail.
* If it's not there, use  to reset the sequence tail, and add a `1` to the recursive result because we needed one extra repetition.

Recursion stops when the decremented copy of the original sequence has 0 as its largest element.

---

@Razetime also shared a “boring Jelly port” in the comments for 8 bytes:

```
1+1⊥2>/⍋

```

# Answer
> 2 votes
# Brachylog, ~~9~~ 8 bytes

```
{⊇Ċ-1}ᶜ<

```

Try it online!

### Explanation

Saved 1 byte by porting everybody else's approach.

```
{⊇Ċ-1}ᶜ<
{    }ᶜ   Count how many ways there are to satisfy this predicate:
 ⊇          A subsequence of the input
  Ċ         Of length 2
   -        Has a difference (first element minus second element)
    1       Equal to 1 (first element is 1 + second element)
       <  The output is the next integer larger than that result

```

---

Old solution that implements the spec directly:

```
;.j₎⊇~o?∧
;           Pair the input with
 .          Some as-yet unknown value which will be the output
  j₎        Repeat the former a number of times equal to the latter (trying 0 first,
            then 1, then 2, etc., until the rest of the predicate succeeds)
    ⊇       Some subsequence of the result
     ~o     Is a sorted version of
       ?    The input
        ∧   Output whatever we calculated earlier as .

```

Try it online!

# Answer
> 1 votes
## Python3, 109 bytes:

```
from itertools import*
f=lambda x,c=1:c if any(sorted(x)==[*i]for i in combinations(x*c,len(x)))else f(x,c+1)

```

Try it online!

Brute force solution, extremely slow.

## Python3, 115 bytes:

```
v=lambda o,n:not o or(o[0]in n and v(o[1:],n[n.index(o[0])+1:]))
f=lambda x,c=1:c if v(sorted(x),x*c)else f(x,c+1)

```

Try it online!

Much faster version.

# Answer
> 1 votes
# JavaScript (ES6), 45 bytes

```
f=(a,k=0)=>a.some(n=>!a[k+=k+1==n])||1+f(a,k)

```

Try it online!

# Answer
> 1 votes
# K (ngn/k), 8 bytes

```
1+/<':<:

```

Try it online!

Essentially a port of @ovs' Jelly answer.

* `<:` grade-up the input (generates a permutation vector which would sort argument into ascending order)
* `<':` check if each value is less than its predecessor
* `1+/` take the sum, seeded with 1

# Answer
> 1 votes
# Desmos, 55 bytes

```
l=sort([1...L.length],L)
f(L)=\total(\{l[2...]<l,0\})+1

```

Try It On Desmos!

Try It On Desmos! - Prettified

\\$f(L)\\$ takes in a list \\$L\\$ and returns the lowest value of \\$t\\$ as specified in the challenge.

The code basically just does the "grade up" trick that many of the other answers were doing.

# Answer
> 1 votes
# Charcoal, 10 bytes

```
ＩΣＥθ›κ⌕θ⊕ι

```

Try it online! Link is to verbose version of code. Based on @dingledooper's observation that the number of repeats is `1` plus the number of times `x+1` appears before `x`, although because `Find` returns `-1` when the value is not found, the formula believes `n+1` appears before `n`, thus automatically adding the extra `1` to the result.

```
   θ        Input array
  Ｅ         Map over values
     κ      Current index
    ›       Is greater than
      ⌕     Index of
         ι  Current value
        ⊕   Incremented
       θ    In input array
 Σ          Take the sum
Ｉ           Cast to string
            Implicitly print

```

# Answer
> 1 votes
# 05AB1E, 6 bytes

```
>kā<‹O

```

The same approach as *@dingledooper*'s uses in his Python answer.

Try it online or verify all test cases.

**Explanation:**

```
>       # Increase each value in the (implicit) input-list by 1
 k      # Get the index of these values in the (implicit) input-list
        # (or -1 for the max+1 that isn't found)
  ā     # Push a list in the range [1,length] (without popping the list)
   <    # Decrease each by 1 to make the range [0,length)
    ‹   # Do a smaller than check for the values of the two lists
     O  # Sum the amount of truthy values
        # (which is output implicitly as result)

```

# Answer
> 1 votes
# Thunno, \\$ 15 \log\_{256}(96) \approx \\$ 12.35 bytes

```
e1+z0AhEDLRz.<S

```

Attempt This Online!

Port of Kevin Cruijssen's 05AB1E answer.

#### Explanation

```
e1+z0AhEDLRz.<S  # Implicit input
e      E         # For each number in the input:
 1+              #  Increment it
     Ah          #  And get the index
   z0            #  in the input (-1 if not found)
        DLR      # Duplicate and push [0..length]
           z.<   # Do a less than check
              S  # Sum the truthy values
                 # Implicit output

```

# Answer
> 1 votes
# Uiua, 10 bytes SBCS

```
+1/+/<⍉◫2⍏

```

Try it!

# Answer
> 1 votes
# Scala 3, 70 bytes

Golfed version. Attempt This Online!

```
_.zipWithIndex.sortBy(_._1).map(_._2).sliding(2).count(p=>p(1)<p(0))+1

```

Ungolfed version.

```
def f(a: Array[Int]): Int = {
    val sortedIndices = a.zipWithIndex.sortBy(_._1).map(_._2)
    sortedIndices.sliding(2).count(pair => pair(1) < pair(0)) + 1
}

```

# Answer
> 0 votes
# C (gcc), ~~70~~ 57 bytes

```
i;t;f(a,n)int*a;{for(i=t=n;t;)a[i%n]+t+~n?i++:t--;a=i/n;}

```

Try it online!

*Saved a whopping 13 bytes thanks to att!!!*

Inputs a pointer to an array of numbers that are a permutation of \\$\\{1, 2 \dots n\\}\\$ and \\$n\\$ (because pointers in C carry no length info).
Returns how many times this array must be repeated before you can *pick out* the numbers \\$\\{1, 2 \dots n\\}\\$ in order.

# Answer
> 0 votes
# Retina 0.8.2, 28 bytes

```
\d+
$*
\b1(1*)\b(?=.*\b\1\b)

```

Try it online! Link includes test cases. Explanation: Uses @dingledooper's observation again.

```
\d+
$*

```

Convert to unary.

```
\b1(1*)\b(?=.*\b\1\b)

```

Count the matches of `1+$.1` that are followed by `$.1`. When this is positive, the word boundary anchors simply ensure that `$.1` is exactly matched, but conveniently when `$.1` is `0` we get an extra "false" match which automatically increments the final result for us.

# Answer
> 0 votes
# Perl 5, 58 bytes

```
sub{$_="@_;"x@_;my$i;1while++$i&&s/.*?\b$i\b//;1+@_-y/;//}

```

Try it online!

# Answer
> 0 votes
# PHP, ~~81~~ ~~74~~ 67 bytes

```
array_reduce($a,function($c,$x){return[$x,$c[1]+($x<$c[0])];})[1]+1

```

Implementation of algorithm from ovs' answer: count all pairs where right \< left, then add 1.

Since array\_reduce takes only one "carry" param, but we want each iteration to know both the running total and the previous value, we make 'carry' be an array with both elements in, which is a few bytes shorter than making a global, but makes a warning the first time we access the (uninitialized) array.

Reduced from first submission by moving all calculation into the return.

Reduced further since it apparently doesn't need to be a program, just a code snippet that takes an array and outputs a value, so all the boilerplate can go away into a header/footer.

Try it online!

---
Tags: code-golf, array, permutations, subsequence
---