Make the Mexican Wave

65

10

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.

absinthe

Posted 2015-07-26T05:40:51.353

Reputation: 8 359

1Is it safe to assume input is never upper case? – Winny – 2015-07-26T05:46:57.483

40@Winny There is no input. The output is fixed. In fact, that's the general idea of [tag:kolmogorov-complexity] questions. – Chris Jester-Young – 2015-07-26T05:49:45.893

This has been in the HNQ list consistently since you posted it. Nice work. :) – Alex A. – 2015-07-30T20:25:25.860

1You can find a reference ungolfed Python implementation here. -> link's broken – Franck Dernoncourt – 2017-08-11T22:48:46.197

Franck Dernoncourt's point still stands. The link is broken. – Jonathan Frech – 2018-07-25T20:18:55.050

Answers

64

Pyth, 12 bytes

V+Gt_GXGNrN1

Demonstration.

In Pyth, G is the lowercase alphabet. +Gt_G is abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba, the character that needs to be uppercased in each row.

V sets up a for loop over this string, with N as the loop variable.

In the body, XGNrN1 is a string translation function. X translates G, the alphabet, replacing N with rN1, the uppercase version of N. r ... 1 is the uppercase function. This gives the desired output.

isaacg

Posted 2015-07-26T05:40:51.353

Reputation: 39 268

31Am I the only one who finds it funny that the lowercase alphabet is represented by an uppercase letter? – Alex A. – 2015-07-31T16:31:51.003

If only the uppercase alphabet is represented by a lowercase letter... – a'_' – 2020-02-28T13:25:19.490

31

C,73

Sometimes the simplest approach is best: print every character one by one. this beats a lot of languages it really shouldn't.

i;f(){for(i=1377;i--;)putchar(i%27?123-i%27-32*!(i/702?i%28-4:i%26):10);}

explanation

i;f(){
   for(i=1377;i--;)
   putchar(i%27?                 //if I not divisible by 27
     123-i%27-                   //  print lowercase letter from ASCII 122 downards
       32*!(i/702?i%28-4:i%26)   //  subtract 32 to make it uppercase where necessary: above i=702, use i%28-4, below it use i%26
     :10);                       //if I divisible by 27 print a newline (10)
}

Level River St

Posted 2015-07-26T05:40:51.353

Reputation: 22 049

26

Python 2, 69 bytes

i=25
exec"L=range(97,123);L[~abs(i)]^=32;i-=1;print bytearray(L);"*51

Nice and simple, I think.

Sp3000

Posted 2015-07-26T05:40:51.353

Reputation: 58 729

That's really clever. Loop unrolling! – Alex Van Liew – 2015-07-31T20:03:15.670

20

Brainfuck (8bit), 231 bytes

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

Ok, so it's never going to be the shortest, but it's the taking part that counts... right?!

Try it here (ensure to tick 'Dynamic memory')

Jarmex

Posted 2015-07-26T05:40:51.353

Reputation: 2 045

5If the goal was to be the longest possible code that is still completely indecipherable to the average human programmer… – Caleb – 2015-07-27T11:15:23.160

7@Caleb I think the BF code is some of the easiest code to understand in existence. It's the program/functionality that's hard to understand. Everyone should know that > shifts one cell to the right, for example. – mbomb007 – 2015-07-27T17:48:03.040

4Always got to love the BF answers ;) – RedPanda – 2015-07-28T07:33:45.850

You didn't write this code directly now did you? – BAR – 2015-07-30T22:32:41.067

6I'm ashamed to say I did! – Jarmex – 2015-07-30T22:40:31.027

13

MS-DOS Binary, 61

This code does not have to be compiled, it will run in MS-DOS if you write it into a file called wave.com . The code in hex:

ba3d0189d7b91a00b061aa404975fbb00aaab00daab024aa31f6e8130046
83fe1a75f7be1800e807004e75fae80100c389d3802820b409cd21800020
c3

Or, if you prefer something more readable, here is how to produce it using debug.exe (the empty line after the code is important):

debug.exe wave.com
a
mov dx,13d
mov di,dx
mov cx,1a
mov al,61
stosb
inc ax
dec cx
jnz 10a
mov al,a
stosb
mov al,d
stosb
mov al,24
stosb
xor si,si
call 130
inc si
cmp si,1a
jnz 11a
mov si,18
call 130
dec si
jnz 126
call 130
ret
mov bx,dx
sub byte ptr [si+bx],20
mov ah,9
int 21
add byte ptr [si+bx],20
ret

rcx
3e
w
q

user2845840

Posted 2015-07-26T05:40:51.353

Reputation: 391

11

Ruby: 71 68 65 63 characters

puts f=(e=*?a..?z).map{|c|(e*"").tr c,c.upcase},f[0,25].reverse

Sample run:

bash-4.3$ ruby -e 'puts f=(e=*?a..?z).map{|c|(e*"").tr c,c.upcase},f[0,25].reverse' | head
Abcdefghijklmnopqrstuvwxyz
aBcdefghijklmnopqrstuvwxyz
abCdefghijklmnopqrstuvwxyz
abcDefghijklmnopqrstuvwxyz
abcdEfghijklmnopqrstuvwxyz
abcdeFghijklmnopqrstuvwxyz
abcdefGhijklmnopqrstuvwxyz
abcdefgHijklmnopqrstuvwxyz
abcdefghIjklmnopqrstuvwxyz
abcdefghiJklmnopqrstuvwxyz

manatwork

Posted 2015-07-26T05:40:51.353

Reputation: 17 865

163: puts f=(e=*?a..?z).map{|c|(e*"").tr c,c.upcase},f[0,25].reverse – Ventero – 2015-07-26T18:20:46.373

Doh. I tried a couple of dumb ideas to optimize e's reuse, but of course not the right way. Thank you, @Ventero. – manatwork – 2015-07-27T07:59:17.240

10

Matlab, 60 58 54 bytes

I=32*eye(26);[ones(51,1)*(97:122) '']-[I;I(25:-1:1,:)])

With thanks to Dennis Jaheruddin for saving me 4 bytes.

Luis Mendo

Posted 2015-07-26T05:40:51.353

Reputation: 87 464

Here you can also use the typical trick to replace char(x) by [x ''] to save a byte. – Dennis Jaheruddin – 2015-07-30T08:58:39.287

Also end-1 is a rather verbose way to write 25! – Dennis Jaheruddin – 2015-07-30T08:59:19.663

@DennisJaheruddin Oops. Thanks for both! Actually the [x ''] trick is not usual at all for me. But now I remember seeing it in one of your anwers :-) – Luis Mendo – 2015-07-30T09:19:30.143

8

Scala 110 109 characters

val a=('a'to'z').map(c⇒('a'to'z').map(v⇒if(v==c)c.toUpper else v).mkString)
a++a.init.reverse foreach println

gilad hoch

Posted 2015-07-26T05:40:51.353

Reputation: 717

5OMG in Scala ⇒ symbol is used? I mean not => but ⇒??? – shabunc – 2015-07-27T23:35:22.997

2Both are valid :) – gilad hoch – 2015-07-28T04:29:57.207

could shave off 1 byte if I change foreach println to mkString("\n"), and output a string as return value instead of printing it to the screen – gilad hoch – 2015-07-29T11:59:14.923

8

SWI-Prolog, 136 bytes

a:-(R=0;R=1),between(1,26,I),(I=1,R=0;I\=1,nl),between(1,26,J),(R=0,L=I;R=1,L is 27-I),(J=L,K is J+64,put(K);J\=L,K is J+96,put(K)),\+!.

Abusing backtracking to loop...

Fatalize

Posted 2015-07-26T05:40:51.353

Reputation: 32 976

8

Haskell 100 89 88 bytes

putStr$map toEnum.(\(h,c:t)->h++c-32:t++[10]).(`splitAt`[97..122]).(25-).abs=<<[-25..25]

The lambda helper function \(h,c:t) takes a pair of lists of ascii values and concatenates both, but with the first value of the second list capitalized. The main function splits the lowercase alphabet (given in ascii, 97..122) at every position 0,..,24,25,24,..,0 and calls the lambda in every step. Before printing each value is turned into the corresponding character.

nimi

Posted 2015-07-26T05:40:51.353

Reputation: 34 639

Here's my approach: http://codegolf.stackexchange.com/a/53895/3852

– Lynn – 2015-07-27T12:37:23.603

7

SQL (postgreSQL), 107 101

Generate are series from -25 to 25 and use the absolute value to replace characters with their uppercase version. Thanks to manatwork for the tip about the @ operator.

select replace('abcdefghijklmnopqrstuvwxyz',chr(122- @i),chr(90- @i))from generate_series(-25,25)a(i)

MickyT

Posted 2015-07-26T05:40:51.353

Reputation: 11 735

You know that PostgreSQL has a @ operator?

– manatwork – 2015-07-26T11:46:24.567

@manatwork nope I didn't know that, but now I do thanks – MickyT – 2015-07-26T12:46:47.780

7

Haskell, 81 bytes

Counting bytes the way @nimi did; f is an IO action that prints the desired output.

x!y|x==min(50-y)y=65|0<1=97
f=mapM putStrLn[[toEnum$x+x!y|x<-[0..25]]|y<-[0..50]]

Lynn

Posted 2015-07-26T05:40:51.353

Reputation: 55 648

Very elegant. Didn't know that guards can be used inline. – user2845840 – 2015-07-29T15:38:57.413

6

Pyth - 18 17 bytes

First pass, probably can be made much shorter. Uses X to substitute and r1 to capitalize.

V+KU26t_KXGNr@GN1

Try it online here.

Maltysen

Posted 2015-07-26T05:40:51.353

Reputation: 25 023

6

MATLAB - 58 bytes

char(bsxfun(@minus,97:122,32*[eye(25,26);rot90(eye(26))]))

Similar to Luis Mendo's solution, but using the broadcasting abilities of bsxfun.

Taking advantage that in ASCII, the difference between a capital and lower case character is exactly 32 values away from each other, we first generate lower case letters from ASCII codes 97 to 122 which are the ASCII codes from lowercase a to lowercase z respectfully, then create a 51 row matrix that contains the 26 ASCII codes from 97 to 122. Therefore, each row of this matrix contains a numerical sequence of values from 97 to 122. Next, we create another matrix where each ith row of this matrix contains a 32 in the ith column. The first 26 rows of this matrix has this pattern, which is essentially the identity matrix multiplied by 32. The function eye creates an identity matrix for you. The last 25 rows of this matrix is the scaled identity matrix rotated 90 degrees.

By taking this custom weighted identity matrix and subtracting this with the first matrix, then converting the resulting ASCII codes into characters, the desired "Mexican Hat" sequence is produced.

Example Run

>> char(bsxfun(@minus,97:122,32*[eye(25,26);rot90(eye(26))]))

ans =

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

You can also run this example using IDEone's online Octave environment. Octave is essentially MATLAB but free: http://ideone.com/PknMe0

rayryeng - Reinstate Monica

Posted 2015-07-26T05:40:51.353

Reputation: 1 521

1rot90 -- well thought! – Luis Mendo – 2015-07-27T13:31:59.350

char(ones(26,1)[97:122] -eye(26)32) – user3528438 – 2015-07-29T17:17:25.797

@user3528438 how do you handle the second half? The code only computes the first half of the wave. You need to compute the rest. – rayryeng - Reinstate Monica – 2015-07-29T17:18:31.117

@user3528438 - Also note that what you wrote is basically the first half of Luis Mendo's answer. I decided to write something a bit different to achieve the same thing :) – rayryeng - Reinstate Monica – 2015-07-29T17:34:55.877

@rayryeng yeah, it suprises me that the second half is harder to handle, and also how to avoid the center duplicate. – user3528438 – 2015-07-29T17:47:16.400

@user3528438 - Yup... the second half is what killed my byte count lol. – rayryeng - Reinstate Monica – 2015-07-29T17:56:01.083

5

PHP, 87 71 69 bytes

Not the shortest one, but it works as intended.
Thanks to @manatwork for a few tips to reduce it's size by a lot.
And thanks to @Blackhole, the size was reduced by 2 bytes.

for(;$L=range(a,z),$L[25-abs($i++-25)]^=' ',$i<52;)echo join($L).'
';

Not exactly pretty, but works.

Ismael Miguel

Posted 2015-07-26T05:40:51.353

Reputation: 6 797

1“glue Defaults to an empty string.” – PHP documentation about join()'s first parameter. – manatwork – 2015-07-26T14:07:02.687

1That string subscript is not really optimal: $i<25?$i:25-($i-25)25-abs($i-25) – manatwork – 2015-07-26T14:16:20.917

1Given that you are already ignoring warnings (for the undefined constants a and z), you could ignore another one for the uninitialized $i. While touching $i, move its incrementation into the string subscript. for(;$i<51;){$L=range(a,z);$L[25-abs($i++-25)]^=" ";echo join($L),"↵";} (Just wrap the line where I used “↵” in the code.) – manatwork – 2015-07-26T14:28:36.693

@manatwork Thanks a lot! I totally forgot that the \n was there. The initialization of $i was left as an accident. And thank you a lot for the 25-abs($i-25). I wouldn't get there by myself. – Ismael Miguel – 2015-07-26T16:40:19.033

2Your for loop can be optimised: for(;$L=range(a,z),$L[25-abs($i++-25)]^=' ',$i<52;)echo join($L).'↵'; (-2 bytes). – Blackhole – 2015-07-27T22:20:40.667

@Blackhole Thanks a lot for the suggestion. It really is a great idea! And it seems to work so far. Once again, thanks a lot for the tip. – Ismael Miguel – 2015-07-27T22:46:39.287

5

J, 31 23 bytes

u:|:(97+i.26)-32*=|i:25

8 bytes saved thanks to @Mauris.

Try it online here.

randomra

Posted 2015-07-26T05:40:51.353

Reputation: 19 909

I could get 23: u:|:(97+i.26)-32*=|i:25 (monad = is really useful here!) – Lynn – 2015-07-27T12:45:07.300

@Mauris Thanks, I haven't thought of using monad = here. It's very nice! – randomra – 2015-07-27T13:44:36.263

5

Perl, 51 bytes

50 bytes code + 1 byte command line parameter

@a=a..z,@a[-1-abs]=uc@a[-1-abs],print@a for-25..25

Can be used as follows:

perl -le '@a=a..z,@a[-1-abs]=uc@a[-1-abs],print@a for-25..25'

Or online here (note I had to add ,"\n" to this as I couldn't add the -l arg).


Much longer method Before the shortened version above, I tried a different method which ended up being pretty chunky. I've left it below anyway for reference.

86 bytes code + 1 byte command line arg

$_=join"",0,a..z,1;print s/1//r while s/(([A-Z])|0)(\D)|(.)((?2))(1)/\L\2\U\3\4\6\L\5/

First Perl I've ever golfed properly so I imagine there's a lot that can be done with it - please do suggest improvements!

Can be used as followed:

perl -le '$_=join"",0,a..z,1;print s/1//r while s/(([A-Z])|0)(\D)|(.)((?2))(1)/\L\2\U\3\4\6\L\5/'

Or online here (note I had to add ."\n" to this as I couldn't add the -l arg).

Explanation

General approach is to use regex substitution to do all the hard work. We start off with:

0abcdefghijklmnopqrstuvwxyz1

This matches (([A-Z])|0)(\D) and gets replaced with \U\3 (\U changes to uppercase) to give:

Abcdefghijklmnopqrstuvwxyz1

From this point onwards, we continue to match the same regex and replace with \L\2\U\3:

aBcdefghijklmnopqrstuvwxyz1
abCdefghijklmnopqrstuvwxyz1
...
abcdefghijklmnopqrstuvwxyZ1

Now the second alternation of the regex matches, (.)((?2))(1) (which is the same as (.)([A-Z])(1)). We replace with \U\4\6\L\5 to give:

abcdefghijklmnopqrstuvwxY1z

This continues to match and replace until we reach:

A1bcdefghijklmnopqrstuvwxyz

and there are no more regex matches.

At each point in the loop we strip off the '1' and print.

Jarmex

Posted 2015-07-26T05:40:51.353

Reputation: 2 045

5

PowerShell 3.0, 82 bytes

$(0..25)+$(24..0)|%{$i=$_;[string](@(97..122)|%{[char]@($_,($_-32))[$_-eq$i+97]})}

Ninj Amint

Posted 2015-07-26T05:40:51.353

Reputation: 51

5

TIS Node Type T21 Architecture - 216 215 bytes

Watch it in action here! There's a DOWN in that video that I later golfed to ANY, but it's functionally identical.

This language has no concept of strings or characters, so I should point out that I'm using ASCII values, i.e. output begins 97, 66, 67...88, 89, 90, 10, 65, 98...

Here's the code in the format of TIS-100's save data, for the purposes of scoring:

@5
ADD 25
L:MOV 27 ANY
SUB 1
JGZ L
MOV 25 ANY
JRO -1
@6
JRO 2
S:MOV 10 ANY
ADD 65
MOV ACC ANY
SUB 90
JEZ S
ADD 26
@9
MOV 32 ANY
ADD UP
L:MOV 0 ANY
SUB 1
JGZ L
@10
MOV UP ACC
ADD ANY
SUB 42
D:JEZ D
ADD 42
MOV ACC ANY

Explanation

undergroundmonorail

Posted 2015-07-26T05:40:51.353

Reputation: 5 897

is this the first question in TIS-100 or what? – noɥʇʎԀʎzɐɹƆ – 2016-07-19T23:47:40.403

1

I have implemented a TIS emulator for TIO, so you can now try it online!

– Phlarx – 2018-05-02T19:54:45.637

4

CJam, 23 bytes

51{25-z~'{,97>'[2$+tN}/

Try it online in the CJam interpreter.

How it works

51{                  }/ e# For I from 0 to 50:
   25-                  e#   Compute J := I - 25.
                        e#   This maps [0 ... 50] to [-25 ... 25].
      z                 e#   Compute K := abs(J).
                        e#   This maps [-25 ... 25] to [25 ... 0 ... 25].
       ~                e#   Compute L := ~K = -(K + 1).
                        e#   This maps [25 ... 0 ... 25] to [-26 ... -1 ... -26].
        '{,             e#   Push ['\0' ... 'z'].
           97>          e#   Discard the first 97. Pushes ['a' ... 'z'].
              '[2$+     e#   Add L to '['. Pushes 'A' for -26, 'Z' for -1.
                   t    e#   Set ['a' ... 'z'][L] to '[' + L.
                    N   e#   Push a linefeed.

Dennis

Posted 2015-07-26T05:40:51.353

Reputation: 196 637

4

JavaScript ES6, 121 bytes

_=>Array(51).fill('abcdefghijklmnopqrstuvwxyz').map((e,i)=>e.replace(/./g,(f,j)=>j==i|i+j==50?f.toUpperCase():f)).join`
`

This is really long because it makes more sense to hardcode the alphabet than to use the absurdly long String.fromCharCode to generate the characters. Test it out below with the Stack snippet, which uses better-supported ES5 and below.

f=function(){
  return Array(51).fill('abcdefghijklmnopqrstuvwxyz').map(function(e,i){
    return e.replace(/./g,function(f,j){
      return j==i|i+j==50?f.toUpperCase():f
    })
  }).join('\n')
}

// Polyfill for ES6-only fill()
Array.prototype.fill = Array.prototype.fill || function(val){
  for(i=0;i<this.length;i++){
    this[i] = val
  }
  return this
}

document.getElementById('p').innerText=f()
<pre id="p"></pre>

NinjaBearMonkey

Posted 2015-07-26T05:40:51.353

Reputation: 9 925

4

R, 78 70

M=replicate(26,c(letters,"\n"));diag(M)=LETTERS;cat(M,M[,25:1],sep="")

Improved by @MickyT

Flounderer

Posted 2015-07-26T05:40:51.353

Reputation: 596

2Almost identical to one I came up with but put to one side. I used M=replicate(26,c(letters,"\n")) rather than a matrix. It will save you a few bytes – MickyT – 2015-07-26T23:15:28.937

4

C#, 140 139 135 132

void f(){int d=1,i=0;var s="abcdefghijklmnopqrstuvwxyz\n";for(;i>=0;i+=d=i==25?-1:d)Console.Write(s.Replace(s[i],(char)(s[i]-32)));}

Expanded

void f()
{
    int d = 1, i =0;
    var s = "abcdefghijklmnopqrstuvwxyz\n";
    for (; i >= 0; i += d = i == 25 ? -1 : d)
        Console.Write(s.Replace(s[i], (char)(s[i] - 32)));
}

Saved 1 byte thanks to @Gunther34567 using a ternary instead of if

Saved 4 bytes then nesting that ternary inside the loop and moving the alphabet to the outside of the loop

Saved 3 bytes combining integer declarations thanks to @eatonphil

BenVlodgi

Posted 2015-07-26T05:40:51.353

Reputation: 361

1you could save 1 byte by changing if(i==25)d=-1; to d=i==25?-1:d; – grabthefish – 2015-07-28T08:39:39.433

1You can save 3 bytes by changing var d=1 to int d=1,i. – eatonphil – 2015-08-01T15:55:16.640

4

Linux Assembly, 289

Unfortunately not competitive with high level languages and probably far from optimal, but pretty straightforward. Run it using nasm -f elf64 -o a.o wave.S; ld -s -o a a.o; ./a (the resulting binary is just 568 bytes big):

section .data
s:db 'abcdefghijklmnopqrstuvwxyz',10
section .text
global _start
_start:
mov esi,0
a:call c
inc esi
cmp esi,26
jne a
mov esi,24
b:call c
dec esi
jnz b
call c
mov eax,1
call d
c:mov ecx,s
sub byte [ecx+esi],32
mov eax,4
mov edx,27
d:mov ebx,1
int 80h
add byte [ecx+esi],32
ret

user2845840

Posted 2015-07-26T05:40:51.353

Reputation: 391

Seems a waste of space to compile this to ELF (lots of bloating zeros there). It can be much reduced if done as a DOS's COM program. I guess it could then run in dosbox in Linux :) – Ruslan – 2015-07-30T05:18:24.877

I know and I did just that. Look at my other post http://codegolf.stackexchange.com/a/53984/42642 :)

– user2845840 – 2015-07-30T12:23:35.050

Yeah, seen it, upvoted it. Didn't notice it was you too though. – Ruslan – 2015-07-30T15:34:22.107

4

x86 assembly for DOS, 41 Bytes compiled

Binary:

00000000  b9 e6 ff b3 61 b8 61 02  50 38 d8 75 02 24 df 88
00000010  c2 cd 21 58 40 3c 7b 75  ef b2 0a cd 21 41 79 02
00000020  43 43 4b 80 f9 19 75 dd  c3

Source code, save as "wave.asm", compile with "nasm -f bin -o wave.com wave.asm" and run with "dosbox wave.com"

org 100h 
section .text
start:
mov cx,-26
mov bl,'a'
next_line:
mov ax, 0261h
next_char:
push ax
cmp al,bl
jnz lower_case
and al,255-32
lower_case:
mov dl,al
int 21h
pop ax
inc ax
cmp al,'z'+1
jnz next_char
mov dl,0ah
int 21h
inc cx
jns move_left
inc bx
inc bx
move_left:
dec bx
cmp cl,25
jnz next_line
ret

Willem

Posted 2015-07-26T05:40:51.353

Reputation: 211

3

Perl - 95 64 bytes

Takes advantage of the fact \u makes the next character printed an uppercase in Perl.

for$c(0..50){$n=1;print map{++$n==27-abs$c-25?"\u$_":$_}a..z,$/}

Thanks to manatwork for saving 31 bytes and fixing it (my previous code did not work.)

ASCIIThenANSI

Posted 2015-07-26T05:40:51.353

Reputation: 1 935

That \u seems to work in a separate sample, but not in your code. :( All characters stayed lowercase. Could you show us how your code should be executed? (I put it in a file then called perl passing it the file name, no switches.) By the way, I use perl 5.20.2. – manatwork – 2015-07-27T10:14:20.383

By the way, it seems to work when \u is followed by the letter to transform in the same string literal: for$c(0..50){$n=1;print map{++$n==27-abs$c-25?"\u$_":$_}a..z,$/} – manatwork – 2015-07-27T10:38:05.127

@manatwork Strange, it worked when I did it. (I use 5.18.) Your code works, and it cuts down the size significantly, so I'll use it. Thanks! – ASCIIThenANSI – 2015-07-29T17:32:09.197

3

Javascript (ES6), 113 bytes

c=-1;while(c++<50){console.log('abcdefghijklmnopqrstuvwxyz'.replace(/./g,(x,i)=>i==c|i+c==50?x.toUpperCase():x))}

110 bytes

for(c=-1;c++<50;)console.log('abcdefghijklmnopqrstuvwxyz'.replace(/./g,(x,i)=>i==c|i+c==50?x.toUpperCase():x))

102 bytes

Old school is unbeatable unless we'll have range operator/function/generator/whatever in js

for(c=-1;c++<50;){for(s='',i=-1;i++<25;)s+=String.fromCharCode(i+(i==c|i+c==50?65:97));console.log(s)}

100 bytes

Unluckily Math.abs is too long

for(c=51;c--;){for(s='',i=26;i--;)s+=String.fromCharCode(c+i==25|c-i==25?90-i:122-i);console.log(s)}

96 94 bytes

Though I've beeing downvoted without explanation I continue my struggle

for(c=-26;c++<25;){for(s='',i=26;i--;)s+=String.fromCharCode(c*c-i*i?122-i:90-i);console.log(s)}

We can shave off a couple of bytes by rearranging loop instructions:

for(c=-26;c++<25;console.log(s))for(s='',i=26;i--;s+=String.fromCharCode(c*c-i*i?122-i:90-i));

shabunc

Posted 2015-07-26T05:40:51.353

Reputation: 169

Please explain downvotes. The output is wrong? – shabunc – 2015-07-28T03:43:48.673

2Maybe because you technically have multiple answers in a single post? Hell if I know, good shaving, though! – Sandy Gifford – 2015-07-29T20:22:28.643

Also, I think you can shave off that last semi-colon – Sandy Gifford – 2015-07-29T20:23:36.563

Nope, I was incorrect – Sandy Gifford – 2015-07-29T20:26:45.803

3

Bash: 76 66 characters

printf -va %s {a..z}
for c in {a..z} {y..a};{ echo ${a/$c/${c^}};}

Sample run:

bash-4.3$ printf -va %s {a..z};for c in {a..z} {y..a};{ echo ${a/$c/${c^}};} | head
Abcdefghijklmnopqrstuvwxyz
aBcdefghijklmnopqrstuvwxyz
abCdefghijklmnopqrstuvwxyz
abcDefghijklmnopqrstuvwxyz
abcdEfghijklmnopqrstuvwxyz
abcdeFghijklmnopqrstuvwxyz
abcdefGhijklmnopqrstuvwxyz
abcdefgHijklmnopqrstuvwxyz
abcdefghIjklmnopqrstuvwxyz
abcdefghiJklmnopqrstuvwxyz

manatwork

Posted 2015-07-26T05:40:51.353

Reputation: 17 865

An anonymous user suggested that the first line is not necessary at all which would reduce the byte count to 45. – Martin Ender – 2015-07-30T17:00:47.113

Interesting. Then from where would the alphabet appear? – manatwork – 2015-07-30T17:19:35.133

I couldn't tell you. The edit simply removed the printf call. I rejected the edit, so you can test it yourself.

– Martin Ender – 2015-07-30T17:24:01.287

Yes, I saw. (The site notified me about the edit and its fate.) As without the 1st line which places the alphabet in variable a, the 2nd line can only print empty strings from variable a, I see no other resolution than rejecting it. :( – manatwork – 2015-07-30T17:27:54.593

3

Sed: 135 119 116 111 characters

(109 character code + 1 character command line option + 1 character input.)

s/.*/abcdefghijklmnopqrstuvwxyz/
h;H;G;H;G;H;g;G
s/.{,28}/\u&/gp
s/$/\t/
:;s/(\w+\n?)\t(.*)/\t\2\1/;t
s/.*Z//

Sample run:

bash-4.3$ sed -rf mexican.sed <<< '' | head
Abcdefghijklmnopqrstuvwxyz
aBcdefghijklmnopqrstuvwxyz
abCdefghijklmnopqrstuvwxyz
abcDefghijklmnopqrstuvwxyz
abcdEfghijklmnopqrstuvwxyz
abcdeFghijklmnopqrstuvwxyz
abcdefGhijklmnopqrstuvwxyz
abcdefgHijklmnopqrstuvwxyz
abcdefghIjklmnopqrstuvwxyz
abcdefghiJklmnopqrstuvwxyz

manatwork

Posted 2015-07-26T05:40:51.353

Reputation: 17 865

2

Jelly, 12 bytes

ØaFŒu⁹¦¥ⱮJŒḄ

Try it online!

ØaFŒu⁹¦¥ⱮJŒḄ
Øa             Lower case alphabet
       ¥       Combine the last two links into a dyad:
  F              Flatten   (1st link)
      ¦          At index... (2nd link)
     ⁹             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.

dylnan

Posted 2015-07-26T05:40:51.353

Reputation: 4 993

How does this work? – lirtosiast – 2019-01-27T02:03:42.450

1@lirtosiast just added an explanation. Let me know if anything is unclear – dylnan – 2019-01-27T18:41:52.257

2

Canvas, 9 bytes

Z\──lz*;n

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 Z\─lz*;n doesn't work as Canvas is too smart and replaces the V in the upside down version with a ^..

dzaima

Posted 2015-07-26T05:40:51.353

Reputation: 19 048

2

Charcoal, 24 12 9 bytes

Eββ↑↗α‖O↑

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

Try it online (verbose) or try it online (pure).

Explanation:

Print the lowercase alphabet with newline delimiter 26 times:

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

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);
‖O↑

Kevin Cruijssen

Posted 2015-07-26T05:40:51.353

Reputation: 67 575

16 maybe? – ASCII-only – 2018-08-06T06:43:29.940

113? 13 using for, also 13 – ASCII-only – 2018-08-06T06:44:28.670

112 :D – ASCII-only – 2018-08-06T06:47:27.777

@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 – 2018-08-06T06:50:45.733

1

My original attempt was 13 bytes but after seeing your answer I golfed it down to 9 bytes.

– Neil – 2019-01-27T10:54:22.917

@Neil Thanks! Didn't even knew about Map and that it could be used like this. – Kevin Cruijssen – 2019-01-27T11:56:36.113

Well, Map returns an array, and the default output for an array is each element on its own line, which saves on explicit newlines! – Neil – 2019-01-27T12:18:00.917

2

VIM, 37 35 bytes

↵ is the enter key

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

JoshM

Posted 2015-07-26T05:40:51.353

Reputation: 379

2

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

Veskah

Posted 2015-07-26T05:40:51.353

Reputation: 3 580

try this 0..25+24..0|%{([char[]]$s=97..122)[$_]-=32;-join$s} :) – mazzy – 2018-07-26T08:25:24.257

1

@mazzy Your version doesn't capitalize the first A -- Try it online!

– AdmBorkBork – 2018-07-26T12:44:56.830

very interesting! Thanks. sceenshot from VS Code and Pure Powershell: https://photos.app.goo.gl/RycqsKGLJinRpnW68

– mazzy – 2018-07-26T12:56:13.893

Why? Any ideas? – mazzy – 2018-07-26T12:58:15.170

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 – 2018-07-26T13:07:04.657

I've found a computer with Windows 7 PS2.0: It capitalize nothing. Curiouser and curiouser! cried Alice https://photos.app.goo.gl/L6L1627JAau9zNGe7

– mazzy – 2018-07-26T16:29:22.160

Well that's very bizarre to say the least. – Veskah – 2018-07-26T20:03:59.183

2

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!

dana

Posted 2015-07-26T05:40:51.353

Reputation: 2 541

2

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

Beta Decay

Posted 2015-07-26T05:40:51.353

Reputation: 21 478

2

q (37 characters)

A first cut

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

skeevey

Posted 2015-07-26T05:40:51.353

Reputation: 4 139

@[.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. – streetster – 2018-06-10T10:56:09.283

2

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.

unclemeat

Posted 2015-07-26T05:40:51.353

Reputation: 2 302

2

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

Trang Oul

Posted 2015-07-26T05:40:51.353

Reputation: 656

2

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

manatwork

Posted 2015-07-26T05:40:51.353

Reputation: 17 865

2

Groovy, 99 88 78 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.

Jon Peterson

Posted 2015-07-26T05:40:51.353

Reputation: 121

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 – 2015-07-27T18:04:31.287

I'm new to golfing. I never thought about reassigning 'it' before. Thanks! – Jon Peterson – 2015-07-27T18:14:23.050

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 – 2015-07-27T19:55:50.850

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 – 2015-07-28T12:51:38.683

2

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

musarithmia

Posted 2015-07-26T05:40:51.353

Reputation: 531

Can you remove the space after A(i)? I program Java, but it seems like you could. – MCMastery – 2015-07-29T15:47:47.473

@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. – 2015-07-31T16:35:15.440

@AlexA. Yes, that's right. The preprocessor needs the space to delimit the macro name from its definition. – musarithmia – 2015-07-31T21:33:38.283

2

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

samgak

Posted 2015-07-26T05:40:51.353

Reputation: 1 577

Shave 3 bytes off by removing the i=0. – steve – 2019-01-27T19:11:26.393

2

><>, 48 bytes

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

"a"&"a"::&:&=84**-o1+:"{"=6$.
=?;&30.~ao&1+:"{"

Sok

Posted 2015-07-26T05:40:51.353

Reputation: 5 592

2

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

enhzflep

Posted 2015-07-26T05:40:51.353

Reputation: 21

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 – 2015-07-29T21:25:44.220

Also save 2 more bytes by moving i++ and n++ to other uses of the variable, gives me 91 bytes. – o11c – 2015-07-29T21:43:18.007

@o11c - thanks for these 2 tips I'd long since forgotten. – enhzflep – 2015-08-26T05:52:20.483

2

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

cameron.bracken

Posted 2015-07-26T05:40:51.353

Reputation: 121

1There 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 – 2015-07-28T23:36:02.707

Short and sweet, very cool! – cameron.bracken – 2015-07-29T22:43:29.610

2

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.

triggerNZ

Posted 2015-07-26T05:40:51.353

Reputation: 251

2

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.

Sven Hohenstein

Posted 2015-07-26T05:40:51.353

Reputation: 2 464

Very nice solution +1 – MickyT – 2015-07-31T21:56:07.947

You can save one byte on your awesome solution. https://tio.run/##K/r/PzmxRCMzryQkP7QkzUIjWaPCRrcoKTMvRcPS3MrQyEg3JTMxXcPITFPL2EjH0EBTpyJax8jUyjBWU1Pz/38A

– JayCe – 2018-06-07T15:40:29.060

@JayCe Thanks for pointing out! – Sven Hohenstein – 2018-06-07T18:29:36.277

1

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.

YGolybev

Posted 2015-07-26T05:40:51.353

Reputation: 111

nice ::println – mazzy – 2018-07-25T13:35:15.497

1

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.
  N       Add a newline.
}/      End loop over position list.

Reto Koradi

Posted 2015-07-26T05:40:51.353

Reputation: 4 870

1

K5, 47 bytes

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

More golfing to come shortly.

kirbyfan64sos

Posted 2015-07-26T05:40:51.353

Reputation: 8 730

1

Mathematica, 104 bytes

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

jcai

Posted 2015-07-26T05:40:51.353

Reputation: 973

1

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

William Barbosa

Posted 2015-07-26T05:40:51.353

Reputation: 3 269

1

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

user20637

Posted 2015-07-26T05:40:51.353

Reputation:

1

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.

Jwosty

Posted 2015-07-26T05:40:51.353

Reputation: 3 530

1

C++, 151 146 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;
    }
}

Johan

Posted 2015-07-26T05:40:51.353

Reputation: 11

1

Haskell, 78 bytes

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.

Baconaro

Posted 2015-07-26T05:40:51.353

Reputation: 279

1

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":""));}}

Online demo

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?

bobbel

Posted 2015-07-26T05:40:51.353

Reputation: 1 037

1

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 – 2018-07-25T13:43:57.310

0

Japt v1.4.5 -R, 12 bytes

;C¬ê £CrX,_u

Try it online!

Somehow tied with top Pyth submission.

Unpacked & How it works

;Cq ê mX{CrX,Z{Zu
;                  Use alternative set of initial variables
 C                 "abc...z"
  q ê              Split into chars and palindromify [a,b,...,z,...,b,a]
      mX{          Map...
         CrX,Z{Zu    Replace the char X in C into uppercase

-R                 Join with newline

Bubbler

Posted 2015-07-26T05:40:51.353

Reputation: 16 616

11 bytes – Shaggy – 2018-06-13T16:46:13.123

Alternative 11 bytes, if you want to stick with r. – Shaggy – 2018-06-13T17:16:55.867

0

Python 2, 107 bytes

a='abcdefghijklmnopqrstuvwxyz'
for c in range(51):
i=25-abs(25-c)
print a[:i]+a[i].upper()+a[i+1:]

Khalil

Posted 2015-07-26T05:40:51.353

Reputation: 49

the diagonals go forwards & back in the output. You're only outputting half of the required output. – dzaima – 2018-06-07T19:29:49.690

Oh, My bad. Ill edit it – Khalil – 2018-06-08T15:59:48.973

0

MS-SQL, 135 bytes

WITH t AS(SELECT-25n UNION ALL SELECT n+1FROM t WHERE n<25)SELECT
STUFF('abcdefghijklmnopqrstuvwxyz',26-ABS(n),1,CHAR(90-ABS(n)))FROM t

Inspired largely by MickyT's postgreSQL solution, but since we can't use generate_series, we use a CTE to create a number table, and use STUFF to replace each character.

BradC

Posted 2015-07-26T05:40:51.353

Reputation: 6 099

0

Yabasic, 93 bytes

An anonymous function that takes no input and outputs to the console.

For i=-25To 25
For j=-25To 0
s$=Chr$(122+j)
If j=-abs(i)Then s$=Upper$(s$)Fi
?s$;
Next
?
Next

Try it online!


Alternate Solution, 93 bytes

For i=-25To 25
For j=-25To 0
s$=Chr$(122+j)
If j+abs(i)Then?s$;Else?Upper$(s$);Fi
Next
?
Next

Try it online!

Taylor Scott

Posted 2015-07-26T05:40:51.353

Reputation: 6 709

0

dc, 83 bytes

97sj1sxBDsy[32-]sU[liddlj=UP1+dsiBD>I]sI[97silIxAPljlx+dsjly!=J]dsJx_1sx96syBBsjlJx

Try it online!

Bit chunkier than I would have liked. Ultimately we're going to use two macros, I and J, and they're going to use some counters, i and j. The counters are decimal values converted to ASCII for printing. Macro I ([liddlj=UP1+dsiBD>I]sI)handles printing one line of the alphabet, letter at a time, checking each letter to see if it matches and running macro U ([32-]sU) to uppercase if need be. It runs until it hits 123, just past the letter 'z'. Macro J ([97silIxAPljlx+dsjly!=J]dsJx) resets i to the beginning of the alphabet, runs I, prints a linebreak (AP), adds the value of x to j, and keeps running as long as it doesn't match the value of y. The first time we run it, x is positive 1 and y is 123, so we increment until we're past the letter 'z'. After doing that, we put j back down to 121 (after ...xyZ we're supposed to print ...xYz and not a second ...xyZ), and set x to negative 1 and y to 96, running J with a decrement and lower bound just below the letter 'a'.

brhfl

Posted 2015-07-26T05:40:51.353

Reputation: 1 291

0

Python 3, 88 bytes

a=list(range(26));[print(''.join([chr([97+x,65+x][x==i])for x in a]))for i in a+a[::-1]]

Try it online!

bobrobbob

Posted 2015-07-26T05:40:51.353

Reputation: 160

0

VBA, 80 bytes

A script that takes no input and outputs to the console.

For i=-25To 25:For j=-25To 0:s=Chr(122+j):?IIf(j+Abs(i),s,UCase(s));:Next:?:Next

Taylor Scott

Posted 2015-07-26T05:40:51.353

Reputation: 6 709

0

Lua, 96 bytes

for j=1,51 do for i=1,26 do io.write(string.char(i+((j+i==52or i==j)and 64or 96)))end print()end

Try it online!


for j=1, 51 do -- a to z (26) + y to a (25), because the Z doesn't repeat
  for i=1, 26 do -- for each letter
     io.write(string.char(i+((j==52-i or j==i) and 64 or 96))) -- ↴
     io.write(string.char(i+(                               )) -- writes the character represented by the value i+(...) on the ASCII table 
                             (j==52-i or j==i)                 -- if the uppercase letter is equal to i or to 52-i
                                               and 64 or 96    -- then sum 64 else sum 96 (because 'A' is 65 and 'a' is 97)
  end
  print() -- jumps to the next line
end

If you have any questions, feel free to ask!

Visckmart

Posted 2015-07-26T05:40:51.353

Reputation: 151

0

Excel, 101 bytes

Using Immediate Window and Output in CellA1:A51

[A1:A51]="=SUBSTITUTE(""abcdefghijklmnopqrstuvwxyz"",CHAR(122-ABS(ROW()-26)),CHAR(90-ABS(ROW()-26)))"

remoel

Posted 2015-07-26T05:40:51.353

Reputation: 511

0

05AB1E, 12 9 bytes

AûvAyDu:,

The existing 05AB1E answer got deleted for some reason, so I decided to post a new one.

-3 bytes thanks to @dzaima.

Try it online.

Explanation:

A           # Push the lowercase alphabet: "abcdefghijklmnopqrstuvwxyz"
 û          # Palindromize it: "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba"
  v         # Loop over each of its characters `y`
   A        #  Push the lowercase alphabet
    y  :    #  Replace the current lowercase letter `y`,
     Du     #  with it's uppercase variant
        ,   #  Print the modified alphabet with trailing newline

Kevin Cruijssen

Posted 2015-07-26T05:40:51.353

Reputation: 67 575

0

Japt -R, 11 bytes

;C£ChYXu̐

Test it

Shaggy

Posted 2015-07-26T05:40:51.353

Reputation: 24 623

0

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

Mojo Jojo

Posted 2015-07-26T05:40:51.353

Reputation: 9

6Welcome 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 – 2015-07-28T11:06:38.457

0

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)

Sandy Gifford

Posted 2015-07-26T05:40:51.353

Reputation: 101

0

Haskell 128 Bytes

import Data.Char
a c=take 701(cycle(toUpper:replicate c id))
f=zipWith($)(a 27++drop 27(a 25))$cycle(['a'..'z']++"\n")
g=f++"z"

Not as short as the others but a very different approach. Defines the constant g as the string. save to a file and open interactively using ghci <filename>. Then enter g to the repl.

HEGX64

Posted 2015-07-26T05:40:51.353

Reputation: 313

0

Python 3, 103 characters

a="abcdefghijklmnopqrstuvwxyz"
for i in range(51):
 x=25-abs(25-i)
 print(a.replace(a[x],a[x].upper()))

Argenis García

Posted 2015-07-26T05:40:51.353

Reputation: 223

Why calculating len(abc) 3 times? It will be always 26. See Tips for golfing in Python for a couple of hints to reduce code size. (By the way, the code you posted has only 141 bytes according to UTF-8 string length & byte counter.)

– manatwork – 2016-02-09T17:39:08.850

2

You keep being one step behind yourself: you fixed the count as 141 and reduced your code to 121 characters.☺ Given that you use long variable name and unnecessarily deep indentation, Tips for golfing in <all languages> may also give you a few golfing hints. And one hint for this particular case: count from 0. That way you can use range(51) and x=25-abs(25-i), which are shorter.

– manatwork – 2016-02-09T17:55:46.620

manatwork, thanks for all the advice, i was taking the size displayed at the file system, instead of the character count. – Argenis García – 2016-02-09T19:54:27.707