# Make the Mexican Wave

In as few bytes as possible, write a program or function that outputs the following:

Abcdefghijklmnopqrstuvwxyz
aBcdefghijklmnopqrstuvwxyz
abCdefghijklmnopqrstuvwxyz
abcDefghijklmnopqrstuvwxyz
abcdEfghijklmnopqrstuvwxyz
abcdeFghijklmnopqrstuvwxyz
abcdefGhijklmnopqrstuvwxyz
abcdefgHijklmnopqrstuvwxyz
abcdefghIjklmnopqrstuvwxyz
abcdefghiJklmnopqrstuvwxyz
abcdefghijKlmnopqrstuvwxyz
abcdefghijkLmnopqrstuvwxyz
abcdefghijklMnopqrstuvwxyz
abcdefghijklmNopqrstuvwxyz
abcdefghijklmnOpqrstuvwxyz
abcdefghijklmnoPqrstuvwxyz
abcdefghijklmnopQrstuvwxyz
abcdefghijklmnopqRstuvwxyz
abcdefghijklmnopqrStuvwxyz
abcdefghijklmnopqrsTuvwxyz
abcdefghijklmnopqrstUvwxyz
abcdefghijklmnopqrstuVwxyz
abcdefghijklmnopqrstuvWxyz
abcdefghijklmnopqrstuvwXyz
abcdefghijklmnopqrstuvwxYz
abcdefghijklmnopqrstuvwxyZ
abcdefghijklmnopqrstuvwxYz
abcdefghijklmnopqrstuvwXyz
abcdefghijklmnopqrstuvWxyz
abcdefghijklmnopqrstuVwxyz
abcdefghijklmnopqrstUvwxyz
abcdefghijklmnopqrsTuvwxyz
abcdefghijklmnopqrStuvwxyz
abcdefghijklmnopqRstuvwxyz
abcdefghijklmnopQrstuvwxyz
abcdefghijklmnoPqrstuvwxyz
abcdefghijklmnOpqrstuvwxyz
abcdefghijklmNopqrstuvwxyz
abcdefghijklMnopqrstuvwxyz
abcdefghijkLmnopqrstuvwxyz
abcdefghijKlmnopqrstuvwxyz
abcdefghiJklmnopqrstuvwxyz
abcdefghIjklmnopqrstuvwxyz
abcdefgHijklmnopqrstuvwxyz
abcdefGhijklmnopqrstuvwxyz
abcdeFghijklmnopqrstuvwxyz
abcdEfghijklmnopqrstuvwxyz
abcDefghijklmnopqrstuvwxyz
abCdefghijklmnopqrstuvwxyz
aBcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz


A trailing newline is permitted. You can find a reference ungolfed Python implementation here.

• Is it safe to assume input is never upper case? – Winny Jul 26 '15 at 5:46
• @Winny There is no input. The output is fixed. In fact, that's the general idea of kolmogorov-complexity questions. – Chris Jester-Young Jul 26 '15 at 5:49
• This has been in the HNQ list consistently since you posted it. Nice work. :) – Alex A. Jul 30 '15 at 20:25
• You can find a reference ungolfed Python implementation here. -> link's broken – Franck Dernoncourt Aug 11 '17 at 22:48
• Franck Dernoncourt's point still stands. The link is broken. – Jonathan Frech Jul 25 '18 at 20:18

# Python 2, 121 bytes

f=[];x=0
for i in[map(chr,range(97,123))]*26:l=i[:];l[x]=l[x].upper();f+=[''.join(l)];x+=1
print'\n'.join(f[:-1]+f[::-1])


This was weird one because of the need to make a copy of i.

For reference, here's the output without making a copy of i:

Abcdefghijklmnopqrstuvwxyz
ABcdefghijklmnopqrstuvwxyz
ABCdefghijklmnopqrstuvwxyz
ABCDefghijklmnopqrstuvwxyz
ABCDEfghijklmnopqrstuvwxyz
ABCDEFghijklmnopqrstuvwxyz
ABCDEFGhijklmnopqrstuvwxyz
ABCDEFGHijklmnopqrstuvwxyz
ABCDEFGHIjklmnopqrstuvwxyz
ABCDEFGHIJklmnopqrstuvwxyz
ABCDEFGHIJKlmnopqrstuvwxyz
ABCDEFGHIJKLmnopqrstuvwxyz
ABCDEFGHIJKLMnopqrstuvwxyz
ABCDEFGHIJKLMNopqrstuvwxyz
ABCDEFGHIJKLMNOpqrstuvwxyz
ABCDEFGHIJKLMNOPqrstuvwxyz
ABCDEFGHIJKLMNOPQrstuvwxyz
ABCDEFGHIJKLMNOPQRstuvwxyz
ABCDEFGHIJKLMNOPQRStuvwxyz
ABCDEFGHIJKLMNOPQRSTuvwxyz
ABCDEFGHIJKLMNOPQRSTUvwxyz
ABCDEFGHIJKLMNOPQRSTUVwxyz
ABCDEFGHIJKLMNOPQRSTUVWxyz
ABCDEFGHIJKLMNOPQRSTUVWXyz
ABCDEFGHIJKLMNOPQRSTUVWXYz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYz
ABCDEFGHIJKLMNOPQRSTUVWXyz
ABCDEFGHIJKLMNOPQRSTUVWxyz
ABCDEFGHIJKLMNOPQRSTUVwxyz
ABCDEFGHIJKLMNOPQRSTUvwxyz
ABCDEFGHIJKLMNOPQRSTuvwxyz
ABCDEFGHIJKLMNOPQRStuvwxyz
ABCDEFGHIJKLMNOPQRstuvwxyz
ABCDEFGHIJKLMNOPQrstuvwxyz
ABCDEFGHIJKLMNOPqrstuvwxyz
ABCDEFGHIJKLMNOpqrstuvwxyz
ABCDEFGHIJKLMNopqrstuvwxyz
ABCDEFGHIJKLMnopqrstuvwxyz
ABCDEFGHIJKLmnopqrstuvwxyz
ABCDEFGHIJKlmnopqrstuvwxyz
ABCDEFGHIJklmnopqrstuvwxyz
ABCDEFGHIjklmnopqrstuvwxyz
ABCDEFGHijklmnopqrstuvwxyz
ABCDEFGhijklmnopqrstuvwxyz
ABCDEFghijklmnopqrstuvwxyz
ABCDEfghijklmnopqrstuvwxyz
ABCDefghijklmnopqrstuvwxyz
ABCdefghijklmnopqrstuvwxyz
ABcdefghijklmnopqrstuvwxyz
Abcdefghijklmnopqrstuvwxyz


# Python 3, 103

a,l='abcdefghijklmnopqrstuvwxyz',list(range(26))
for i in l+l[24::-1]:print(a[:i]+a[i].upper()+a[i+1:])


or, without hardcoding alphabet:

l,a=list(range(26)),''.join(chr(i+97)for i in l)
for i in l+l[24::-1]:print(a[:i]+a[i].upper()+a[i+1:])


C (208 characters)

(my first try at Code Golf)

#include<stdio.h>
#define P printf
#define A(i) {for(l='a',p=0;l<='z';++l,++p){if(p==i)P("%c",l-32);else P("%c",l);}P("\n");}
int main(){int i,p;char l;for(i=0;i<26;++i)A(i);for(i=24;i>=0;--i)A(i);return 0;}

• Can you remove the space after A(i)? I program Java, but it seems like you could. – MCMastery Jul 29 '15 at 15:47
• @MCMastery I don't think so since it's in a #define. It's defining A(i) to hold the value {for...;}, and the statement needs the space to differentiate symbol from value. (I think that's right but I could be wrong.) – Alex A. Jul 31 '15 at 16:35
• @AlexA. Yes, that's right. The preprocessor needs the space to delimit the macro name from its definition. – musarithmia Jul 31 '15 at 21:33

## Batch - 284 bytes

@!! 2>nul||cmd/q/v/c%0&&exit/b
set a=&for /l %%a in (65,1,90)do (set/aa+=1,b=0&cmd/cexit %%a&set c=!=exitCodeAscii!&for /L %%b in (97,1,122)do set/ab+=1&cmd/cexit %%b&if !a!==!b! (set %%a=!%%a!!c!)else set %%a=!%%a!!=exitCodeAscii!
echo !%%a!)
for /l %%a in (89,-1,65)do echo !%%a!


Ungolfed:

@echo off
setLocal enableDelayedExpansion
set a=0
for /l %%a in (65,1,90) do (
set /a a+=1,b=0
cmd /c exit %%a
set c=!=exitCodeAscii!
for /L %%b in (97,1,122) do (
set /a b+=1
cmd /c exit %%b
if !a!==!b! (
set %%a=!%%a!!c!
) else set %%a=!%%a!!=exitCodeAscii!
)
echo !%%a!
)
for /l %%a in (89,-1,65) do echo !%%a!


To get the alphabets, this uses the !=exitCodeAscii! variable generated from new CMD instances (knowing that 65 to 90 is A to Z, and 97 to 122 is a to z). Just hard-coding the alphabets could very well be shorter, but this is much cuter.

# awk, 91 bytes

awk 'BEGIN{for(i=0;i<51;i++)for(j=0;j<27;j++)printf("%c",j>25?10:i==j||j==50-i?j+65:j+97)}'

• Shave 3 bytes off by removing the i=0. – steve Jan 27 '19 at 19:11

## ><>, 48 bytes

Just playing around with the . operator more than anything else.

"a"&"a"::&:&=84**-o1+:"{"=6$. =?;&30.~ao&1+:"{"  C - 110 bytes Golfed void f(){int i,n=0,c=0;for(;n<51;n++){for(i=0;i<26;i++)putchar((i==c)?i+65:i+97);c+=(n>24?-1:1);putchar(10);}}  Ungolfed void f() { int i,n,c=0; for(n=0;n<51;n++) { for(i=0;i<26;i++) putchar((i==c)?i+'A':i+'a'); c+=(n>24?-1:1); putchar(10); } }  • Unnecessary parens in (i==c)?: and c+=(); if you use global variables they are initialized to 0 automatically; int is implicit (also don't use void). – o11c Jul 29 '15 at 21:25 • Also save 2 more bytes by moving i++ and n++ to other uses of the variable, gives me 91 bytes. – o11c Jul 29 '15 at 21:43 • @o11c - thanks for these 2 tips I'd long since forgotten. – enhzflep Aug 26 '15 at 5:52 ## Groovy, 998878 77 bytes ((a='a'..'z')+('y'..'a')).each{println a.join().replace(it,it.toUpperCase())}  Thanks to manatwork for helping me trim off 11 21 bytes. • With some usual golfing tricks applied: 51.times{println(('a'..'z').join().replace((char)it=25-Math.abs(25-it)+97,(char)it-32))} – manatwork Jul 27 '15 at 18:04 • I'm new to golfing. I never thought about reassigning 'it' before. Thanks! – Jon Peterson Jul 27 '15 at 18:14 • 78 characters: ((a='a'..'z')+('y'..'a')).each{println(a.join().replace(it,it.toUpperCase()))} (Watch out when copying code from a comment. The site seems to insert some invisible multibyte characters in them. My previous code was 88 characters, not 90.) – manatwork Jul 27 '15 at 19:55 • Awesome. Way more elegant and easy to read as well. I had no idea you could add ranges. Learning something every day! I removed the parenthesis around println to lower one more byte. – Jon Peterson Jul 28 '15 at 12:51 # R 72 Since there are no R answers: a=function(i){l=letters;l[i]=toupper(l[i]);l};for(i in c(1:26,25:1))cat(a(i),'\n',sep='')  • There is already an R answer, but yours beats it if you make the function anonymous: for(i in c(1:26,25:1))cat([<-(letters,i,LETTERS[i]),'\n',sep="") – Flounderer Jul 28 '15 at 23:36 • Short and sweet, very cool! – cameron.bracken Jul 29 '15 at 22:43 Scala - 103 (0.to(25)++24.to(0,-1))map{i⇒val a=(97+i)toChar;println('a'to('z')mkString("")replace(a,a.toUpper))}  Some fun postfix operator abuse. # jq: 99 characters (96 characters code + 3 characters command line option.) "abcdefghijklmnopqrstuvwxyz"as$a|range(51)|[.,50-.]|min|$a[:.]+($a[.:.+1]|ascii_upcase)+$a[.+1:]  Sample run: bash-4.3$ jq -n -r '"abcdefghijklmnopqrstuvwxyz"as$a|range(51)|[.,50-.]|min|$a[:.]+($a[.:.+1]|ascii_upcase)+$a[.+1:]' | head
Abcdefghijklmnopqrstuvwxyz
aBcdefghijklmnopqrstuvwxyz
abCdefghijklmnopqrstuvwxyz
abcDefghijklmnopqrstuvwxyz
abcdEfghijklmnopqrstuvwxyz
abcdeFghijklmnopqrstuvwxyz
abcdefGhijklmnopqrstuvwxyz
abcdefgHijklmnopqrstuvwxyz
abcdefghIjklmnopqrstuvwxyz
abcdefghiJklmnopqrstuvwxyz


On-line test (Passing -r through URL is not supported – check Raw Output yourself.)

## R, 60 59

cat(intToUtf8(c(x<-rbind(97:122-diag(26)*32,10),x[,25:1])))


Improvement based on the comment by @JayCe.

Former version:

x=rbind(97:122-diag(26)*32,10)
cat(intToUtf8(c(x,x[,25:1])))


This is based on ASCII codes that are transformed to characters.

• Very nice solution +1 – MickyT Jul 31 '15 at 21:56
• You can save one byte on your awesome solution. tio.run/##K/r/… – JayCe Jun 7 '18 at 15:40
• @JayCe Thanks for pointing out! – Sven Hohenstein Jun 7 '18 at 18:29

# Canvas, 9 bytes

Ｚ＼──ｌｚ＊；ｎ


Try it here!

This also works in the latest version, but didn't before this commit (..yes it was used), so the link is to an older version of Canvas.

Explanation:

Z\--lz*;n
Z          push the uppercase alphabet
\         create a diagonal out of that
--       palindromize vertically with 1 overlap
l      get the height of that
z*    and repeat the lowercase alphabet vertically that many times
;n  overlap the diagonals over the lowercase block of alphabet


unfortunately Ｚ＼─ｌｚ＊；ｎ doesn't work as Canvas is too smart and replaces the V in the upside down version with a ^..

VIM, 37 35 bytes

↵ is the enter key

:h<_↵jjYZZ51P25@='vUlj'↵26@='vUjh'↵


# C# (Visual C# Interactive Compiler), 81 bytes

int i,j;for(;i<1376;j=++i%27)Write((char)(j>25?10:j+(i/27==j|i/27==50-j?65:97)));


Try it online!

My answer uses a similar strategy to this C answer, but I came up with it independently.

For the heck of it, here is a solution that decrements the loop variable, (like the C solution), but it is not quite as short as the solution that increments.

# C# (Visual C# Interactive Compiler), 86 bytes

for(int i=1377,j;i-->0;)Write((char)((j=i%27)<1?10:(i/27==j+24|i/27==26-j?91:123)-j));


Try it online!

# Charcoal, 2412 9 bytes

Ｅββ↑↗α‖Ｏ↑


-12 bytes thanks to @ASCII-only.
-3 bytes thanks to @Neil.

Explanation:

Print the lowercase alphabet with newline delimiter 26 times:

Print(Map(b, b));
Ｅββ


Move up once:

Move(:Up);
↑


Print the uppercase alphabet in an up-right direction:

Print(:UpRight, a);
↗α


Reflect everything upwards horizontally with one line overlap:

ReflectOverlap(:Up);
‖Ｏ↑

• 16 maybe? – ASCII-only Aug 6 '18 at 6:43
• – ASCII-only Aug 6 '18 at 6:44
• 12 :D – ASCII-only Aug 6 '18 at 6:47
• @ASCII-only I was just done editing the page, lol.. Here we go again. Thanks though! I knew this could be golfed by a lot, but you've just halved it. :D – Kevin Cruijssen Aug 6 '18 at 6:50
• My original attempt was 13 bytes but after seeing your answer I golfed it down to 9 bytes. – Neil Jan 27 '19 at 10:54

# Jelly, 12 bytes

ØaFŒu⁹¦¥ⱮJŒḄ


Try it online!

ØaFŒu⁹¦¥ⱮJŒḄ
Øa             Lower case alphabet
⁹             right argument to the dyad defined by ¥...
Œu              Make upper case.
Ɱ      Do the dyad defined by ¥ at each element of the right argument:
J     [1...26] (len of the alphabet)
This gives ["Abc..", "aBc...",... ,"...xyZ"]
ŒḄ   Bounce. i.e. take the list above, remove the last element, reverse
and append to the original argument.
This leaves a list of lines which can be printed properly with Y.

• How does this work? – lirtosiast Jan 27 '19 at 2:03
• @lirtosiast just added an explanation. Let me know if anything is unclear – dylnan Jan 27 '19 at 18:41

# PowerShell, 53 bytes

0..25+24..0|%{($s=[char[]](97..122))[$_]-=32;-join$s}  Try it online! Each iteration makes a fresh array of a-z, capitalizes the correct one by shifting its ASCII value, then joins it into a proper line • try this 0..25+24..0|%{([char[]]$s=97..122)[$_]-=32;-join$s} :) – mazzy Jul 26 '18 at 8:25
• @mazzy Your version doesn't capitalize the first A -- Try it online! – AdmBorkBork Jul 26 '18 at 12:44
• very interesting! Thanks. sceenshot from VS Code and Pure Powershell: photos.app.goo.gl/RycqsKGLJinRpnW68 – mazzy Jul 26 '18 at 12:56
• Why? Any ideas? – mazzy Jul 26 '18 at 12:58
• ps5.1, pwsh 6.0.2, pwsh 6.1.0-preview4 for Linux, VS Code Integrated Console 6.0.2 doesn't capitalize the first A. Ok, assume it's special behavior of VS Code Integrated Console 5.1. Why they doesn't capitalize? – mazzy Jul 26 '18 at 13:07

# CJam, 26 bytes

26,:L_W<W%+{L'af+\_'A+tN}/


Try it online

Explanation:

26,     Create sequence [0 .. 25].
:L      Store it in variable for later reuse.
_       Copy.
W<      Slice off last element to get [0 .. 24]
W%      Reverse it to get [24 .. 0]
+       Concatenate to get [0 .. 25 .. 0]
{       Loop over position list.
L'af+   Build [a .. z] by adding 'a to previously saved [0 .. 25]
\_      Pop position to top, and copy it.
'A+     Calculate upper case letter by adding 'A to position.
t       Store upper case letter in sequence.
}/      End loop over position list.


# K5, 47 bytes

(0:)'{c\$(97+!x),(x+65),97+1_x_l}'l,1_|(l:!26)


More golfing to come shortly.

# Mathematica, 104 bytes

FromCharacterCode[#~Join~Rest@Reverse@#]<>""&[{##,10}&@@@(97~Range~122~Table~{26}-32IdentityMatrix@26)]


# Clojure, 125 (ugh)

(map println(map #(apply str(replace{(char(+ %(int\a)))(char(+ %(int\A)))}%2))(range 26)(repeat 26(map char(range 97 123)))))


# F#: 114 characters

Simple, and a little naïve -- can't really think of any other way to shorten the technique I used here. I'm sure there's a different approach that would be shorter.

Seq.map(fun i->(for c in 97..122 do printf"%c"(char(if c=i then c-32 else c)));printfn"")<|[97..122]@[122..-1..97]


Explanation: iterate the alphabet twice (forward then backwards) with Seq.map ... [97..122]@[122..-1..97], the printing the alphabet each time but with the current character capitalized.

## C++, 151146 142

Golfed:

#include <iostream>
int main(){int a=1,b=0,j;while(b>-1){for(j=0;j<27;j++){std::cout<<(char)(j>25?'\n'j:j==b?'A'+j:'a'+j);}b+=a;b>24?a=-1:a;}}


Ungolfed:

int main(){
int a=1,b=0,j;
while(b>-1) {
for(j=0;j<27;j++){
std::cout << (char)(j>25?'\n':j==b?'A'+j:'a'+j);
}
b+=a;
b>24?a=-1:a;
}
}


mapM_ putStrLn[['a'..toEnum(x-2)]++toEnum(x-33):[toEnum(x)..'z']|x<-[98..123]]


This code takes for all 'numbers, x from 'a'(+1) to 'z'(+1):

• the letters from a to the letter corresponding to x-2
• the letter x-33 (x-1 uppercased)
• the letters from the letter corresponding to x It concatenes them. We have the list of the strings. We print it.

## F# - 141

This is my first try in F#. I would love some feedback :)

[97..122]@List.rev [97..121]|>Seq.iter(fun x->[97..122]|>Seq.map(fun y->(char(y-if x=y then 32 else 0)))|>System.String.Concat|>printfn "%s")


# Kotlin, 121 bytes

Array(26){"abcdefghijklmnopqrstuvwxyz"}.mapIndexed{i,s->s.replace(s[i],s[i]-32)}.let{it+it.reversed()}.forEach(::println)


Try it online!

Generates array of alphabet string with alphabet size, and then replacing characters to uppercase characters, after concacts resulting list and its reversed version.

• nice ::println – mazzy Jul 25 '18 at 13:35

# Java, 159 158 bytes

class A{public static void main(String[]a){for(int b=0;b++<51;)for(int c=70;c++<96;)System.out.print((char)(c+(96-Math.abs(b-26)==c?-6:26))+(c>95?"\n":""));}}


Try it online

## Explanation

class A {
public static void main(String[] a) {
// loop the alphabet two times (2 x 26)
for (int b = 0; b++ < 51;) {
// loop from lower character ASCII codes a (97) to z (122)
// c will be from [71 to 96] (because of condition "c++" before the first iteration)
for (int c = 70; c++ < 96;) {
System.out.print(
// print character by ASCII code
(char)(c + (
// if character position matches the wave
96 - Math.abs(b - 26) == c
// substract 6, because 71 - 6 = 65 = 'A'
? -6
// otherwise add 26, because 71 + 26 = 97 = 'a'
: 26)
) +
// if current character is greater then the 'y' (ASCII 95), also print a new line
(c > 95 ? "\n" : "")
);
}
}
}
}


Perhaps there's too much math in this. Someone who can shorten this?

• I know it's been almost three years, but you can golf 8 bytes like this: interface A{static void main(String[]a){for(int b=0,c;b++<51;)for(c=70;c++<96;)System.out.printf("%c%s",96-Math.abs(b-26)==c?c-6:c+26,c>95?"\n":"");}}. Summary of changes: class to interface so you can remove public; int b=0; and int c=70; to int b=0,c; and c=70;; System.out.print((char)(...)+(...)); to System.out.printf("%c%s",...,...);; c+(...?-6:26) to ...?c-6:c+26 to get rid of the parenthesis. Try it online: 150 bytes. nice answer though, +1 from me. :) – Kevin Cruijssen Jul 25 '18 at 13:43

# Java: 918 characters

public class Sample{

public static int i;

public static int j;

public static int z;

public static String[] k={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};

public static void main(String args[]){
for (i=0; i<k.length;i++){
for(j=0 ;j<k.length;j++){
if (i==j){
System.out.print(k[j].toUpperCase());
}
else
System.out.print(k[j].toLowerCase());
}
System.out.println();
}
for (i=1; i<k.length;i++){
for(j=0 ;j<k.length;j++){
if (i==(k.length-(j+1))){
System.out.print(k[j].toUpperCase());
}
else
System.out.print(k[j].toLowerCase());
}
System.out.println();
}
}
}

• Welcome to PPCG! This is code golf, so the goal is to solve the problem with as few bytes of code as possible. For a start you could get rid of all the unnecessary whitespace amd braces. – Martin Ender Jul 28 '15 at 11:06

# ECMAScript 6 - 114 110 characters

(112 108 + 2 linebreaks)

b=(c,d)=>c<26?String.fromCharCode(c==d?c+65:c+97)+b(c+1,d):""
a=i=>b(0,i)+(i?"\n"+a(i-1)+"\n"+b(0,i):"")
a(25)


Two recursive functions a and b:

• b creates an alphabet string with the letter at index d capitalized. Doesn't take very much advantage of recursion, but fat arrows make this function just a tiny bit shorter than a loop.
• a creates line by line anagrams (sort of) of the strings generated by b

EDIT: Woops! The capitalization is backwards ('z' is capitalized on the first and last line, 'a' in the middle)