# 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? 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. Jul 26 '15 at 5:49
• This has been in the HNQ list consistently since you posted it. Nice work. :) Jul 30 '15 at 20:25
• You can find a reference ungolfed Python implementation here. -> link's broken Aug 11 '17 at 22:48
• Franck Dernoncourt's point still stands. The link is broken. Jul 25 '18 at 20:18

# 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? Jan 27 '19 at 2:03
• @lirtosiast just added an explanation. Let me know if anything is unclear Jan 27 '19 at 18:41

# jq -nr, 58 bytes

range(51)-25|fabs as$a|[range(26)+97]|.[25-$a]-=32|implode


Try it online with .*.|sqrt instead of fabs, or try it on https://jqplay.org/ with input "" and Raw output.

# jq-nr, 7772 70 bytes

The first part up to min is taken from manatwork's answer

range(51)|[.,50-.]|min|[. as$i|range(26)|.+(.-$i|.?/.*97//65)]|implode


Try it online!

range(51)|[.,50-.]|min generates a sequence of the indices of uppercase letters

|[ ... ] maps the inner part for each index and collects the results in one array for each index:
. as$x store current uppercase index in $x
range(26) range from 0 to 25
.+(.-$i|try./.*97//65) get the codepoint for that alphabet index, uppercase if it matches $x, lowercase if not. try./.*97 returns empty for 0/0, which gets replaced with 65 by //65 (I think that's how that works)

|implode converts each array of codepoints into a string

• Nice! Unfortunately, I can't award a +50 bounty for this as I've already answered this. Sep 4 at 10:42

# q (37 characters)

A first cut

@[.Q.a;;upper]'[(raze(|:\)til 26)_26]

• @[.Q.a;;upper]@'x,1_reverse x:til 26 for 36 bytes. Or @[.Q.a;;.q.upper]@'x,1_|x:!26 for 29 bytes in K4.
– mkst
Jun 10 '18 at 10:56

# 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


# K5, 47 bytes

(0:)'{c$(97+!x),(x+65),97+1_x_l}'l,1_|(l:!26)  More golfing to come shortly. # 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. 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.) Jul 31 '15 at 16:35 • @AlexA. Yes, that's right. The preprocessor needs the space to delimit the macro name from its definition. Jul 31 '15 at 21:33 • 106 bytes Mar 9 '20 at 7:37 ## 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. ## ><>, 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. 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))} Jul 27 '15 at 18:04
• I'm new to golfing. I never thought about reassigning 'it' before. Thanks! 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.) 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. 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="") Jul 28 '15 at 23:36
• Short and sweet, very cool! 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 Jul 31 '15 at 21:56 • You can save one byte on your awesome solution. tio.run/##K/r/… Jun 7 '18 at 15:40 • @JayCe Thanks for pointing out! 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 ^.. • Came up with a(longer) different version: Ｚ＼ｚ┌ｌ；┐＊；ｎ Oct 31 '20 at 15:59 • @Razetime that doesn't do the vertical palendromizing. And you could've done ‾¶ instead of ┌ｌ；┐ Nov 1 '20 at 9:35 • works, but not palidromized Nov 1 '20 at 9:40 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? Aug 6 '18 at 6:43 • Aug 6 '18 at 6:44 • 12 :D 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 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 # 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} :) Jul 26 '18 at 8:25 • @mazzy Your version doesn't capitalize the first A -- Try it online! Jul 26 '18 at 12:44 • very interesting! Thanks. sceenshot from VS Code and Pure Powershell: photos.app.goo.gl/RycqsKGLJinRpnW68 Jul 26 '18 at 12:56 • Why? Any ideas? 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? Jul 26 '18 at 13:07 # Vimscript - 41 bytes/keystrokes ia<Esc>qqylp<C-a>q24@qY51pk^qw~jq25@whqs~hjhq25@s  Make sure that alphabet increment is enabled: set nrformats+=alpha  ## Explanation: ia<Esc>qqylp<C-a>q24@q writes down the alphabets from 'a' to 'z'. Y50p copies the line and paste it 50 times. k^ moves cursor to letter 'a' on the first line. qw~jq starts recording, changes the 'a' to uppercase moves the cursor down and stops recording 25@w replays the record 25 times hqs~hjhq starts recording, moves the cursor to 'y', changes 'y' to uppercase moves the cursor down left and stops recording 25@s replays the record 25 times • Welcome to the site, and nice first answer! We typically score vim by keystrokes (counting e.g. <Esc> as 1 keystroke/byte) and by my count this is 41keystrokes. Also, check out our Tips for golfing in Vim page for ways you can golf your code Jan 10 at 7:56 • @cairdcoinheringaahing thank you for the feedback, I'll check out the tips too! Jan 10 at 14:49 # Vyxalj, 11 bytes kaømƛ:⇧ka∇V  Try it Online! ka # Lowercase alphabet øm # Palindromised ƛ # Map... : ∇V # Replace that character ⇧ # With its uppercase ka # In the lowercase alphabet  # jq -nr, 93 89 bytes [range(26)+97]|. as$a|range(51)|[.,50-.]|min|$a[:.]+($a[.:.+1]|[.[]-32])+$a[.+1:]|implode  Try it online! porting manatwork's idea. -4 bytes from ovs. # jq -nr, 95 bytes [range(26)+97]|implode|. as$i|./""|[.[]as$j|$i|sub($j;$j|ascii_upcase)]|.+reverse[1:]|join("
")


Try it online!

removing the variables might increase the size. Having explicit references is useful sometimes.

-n is for no input.

-r is to output the string raw. Otherwise it is printed with \n instead of actual newlines.

• If you move implode to the end, can you save a few bytes by using .-32 instead of ascii_upcase? I couldn't get it to work but I have no experience with this language
– ovs
Sep 4 at 8:30
• i'm not perfect sure how manatwork's answer works myself. i will tell you if i manage to get it right Sep 4 at 8:49
• @ovs got it working! Sep 4 at 8:51

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


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


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