63
\$\begingroup\$

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.

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

74 Answers 74

2
\$\begingroup\$

q (37 characters)

A first cut

@[.Q.a;;upper]'[(raze(|:\)til 26)_26]
\$\endgroup\$
  • \$\begingroup\$ @[.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. \$\endgroup\$ – streetster Jun 10 '18 at 10:56
2
\$\begingroup\$

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

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:])
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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)}'
\$\endgroup\$
  • \$\begingroup\$ Shave 3 bytes off by removing the i=0. \$\endgroup\$ – steve Jan 27 at 19:11
2
\$\begingroup\$

><>, 48 bytes

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

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

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);
    }
}
\$\endgroup\$
  • \$\begingroup\$ 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). \$\endgroup\$ – o11c Jul 29 '15 at 21:25
  • \$\begingroup\$ Also save 2 more bytes by moving i++ and n++ to other uses of the variable, gives me 91 bytes. \$\endgroup\$ – o11c Jul 29 '15 at 21:43
  • \$\begingroup\$ @o11c - thanks for these 2 tips I'd long since forgotten. \$\endgroup\$ – enhzflep Aug 26 '15 at 5:52
2
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ With some usual golfing tricks applied: 51.times{println(('a'..'z').join().replace((char)it=25-Math.abs(25-it)+97,(char)it-32))} \$\endgroup\$ – manatwork Jul 27 '15 at 18:04
  • \$\begingroup\$ I'm new to golfing. I never thought about reassigning 'it' before. Thanks! \$\endgroup\$ – Jon Peterson Jul 27 '15 at 18:14
  • \$\begingroup\$ 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.) \$\endgroup\$ – manatwork Jul 27 '15 at 19:55
  • \$\begingroup\$ 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. \$\endgroup\$ – Jon Peterson Jul 28 '15 at 12:51
2
\$\begingroup\$

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='')
\$\endgroup\$
  • 1
    \$\begingroup\$ 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="") \$\endgroup\$ – Flounderer Jul 28 '15 at 23:36
  • \$\begingroup\$ Short and sweet, very cool! \$\endgroup\$ – cameron.bracken Jul 29 '15 at 22:43
2
\$\begingroup\$

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.

\$\endgroup\$
2
\$\begingroup\$

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

\$\endgroup\$
2
\$\begingroup\$

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.

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

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

\$\endgroup\$
2
\$\begingroup\$

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!

\$\endgroup\$
2
\$\begingroup\$

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↑
\$\endgroup\$
  • \$\begingroup\$ 16 maybe? \$\endgroup\$ – ASCII-only Aug 6 '18 at 6:43
  • 1
    \$\begingroup\$ 13? 13 using for, also 13 \$\endgroup\$ – ASCII-only Aug 6 '18 at 6:44
  • 1
    \$\begingroup\$ 12 :D \$\endgroup\$ – ASCII-only Aug 6 '18 at 6:47
  • \$\begingroup\$ @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 \$\endgroup\$ – Kevin Cruijssen Aug 6 '18 at 6:50
  • 1
    \$\begingroup\$ My original attempt was 13 bytes but after seeing your answer I golfed it down to 9 bytes. \$\endgroup\$ – Neil Jan 27 at 10:54
2
\$\begingroup\$

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.
\$\endgroup\$
  • \$\begingroup\$ How does this work? \$\endgroup\$ – lirtosiast Jan 27 at 2:03
  • 1
    \$\begingroup\$ @lirtosiast just added an explanation. Let me know if anything is unclear \$\endgroup\$ – dylnan Jan 27 at 18:41
2
\$\begingroup\$

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

\$\endgroup\$
  • \$\begingroup\$ try this 0..25+24..0|%{([char[]]$s=97..122)[$_]-=32;-join$s} :) \$\endgroup\$ – mazzy Jul 26 '18 at 8:25
  • 1
    \$\begingroup\$ @mazzy Your version doesn't capitalize the first A -- Try it online! \$\endgroup\$ – AdmBorkBork Jul 26 '18 at 12:44
  • \$\begingroup\$ very interesting! Thanks. sceenshot from VS Code and Pure Powershell: photos.app.goo.gl/RycqsKGLJinRpnW68 \$\endgroup\$ – mazzy Jul 26 '18 at 12:56
  • \$\begingroup\$ Why? Any ideas? \$\endgroup\$ – mazzy Jul 26 '18 at 12:58
  • \$\begingroup\$ 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? \$\endgroup\$ – mazzy Jul 26 '18 at 13:07
1
\$\begingroup\$

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

K5, 47 bytes

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

More golfing to come shortly.

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

Mathematica, 104 bytes

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

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

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.

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

Java, 219 bytes

Golfed:

class A{public static void main(String[]z){char[]a="abcdefghijklmnopqrstuvwxyz".toCharArray();for(int i=0;i<25;a[i++]+=32){a[i]-=32;System.out.println(a);}for(int i=25;i>=0;a[i--]+=32){a[i]-=32;System.out.println(a);}}}

Ungolfed:

class A {
    public static void main(String[] z) {
        char[] a = "abcdefghijklmnopqrstuvwxyz".toCharArray();
        for (int i = 0; i < 25; a[i++] += 32) {
            a[i] -= 32;
            System.out.println(a);
        }
        for (int i = 25; i >= 0; a[i--] += 32) {
            a[i] -= 32;
            System.out.println(a);
        }
    }
}

It is fairly simple. It creates an alphabet array. It prints it out 26 times, while capitalizing the i'th letter and decapitalizing the previous one.

This is my first code golf, so tips for improvement would be appreciated :-)

\$\endgroup\$
  • 1
    \$\begingroup\$ Welcome to PPCG! We usually expect submissions to be full programs or functions (where lambdas and other unnamed functions are legitimate), not just code snippets. Otherwise, keep it up! :) \$\endgroup\$ – Martin Ender Jul 27 '15 at 0:29
  • 1
    \$\begingroup\$ I made a few modifications to your program to make it more interesting to watch ;) (run in terminal with javac A.java && java A) class A { public static void main(String[] z) { char[] a = "abcdefghijklmnopqrstuvwxyz".toCharArray(); for (int i = 0; i < 26; a[i++] += 32) { a[i] -= 32; System.out.print("\r" + java.util.Arrays.toString(a)); try{Thread.sleep(200);}catch (Exception e){} } } } \$\endgroup\$ – James Webster Jul 27 '15 at 11:10
  • \$\begingroup\$ But this is only one way, right? The example output does it one way and then the other. \$\endgroup\$ – JackWhiteIII Jul 31 '15 at 12:19
  • \$\begingroup\$ @JackWhiteIII Good catch! Fixed. \$\endgroup\$ – Evorlor Jul 31 '15 at 18:52
1
\$\begingroup\$

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;
    }
}
\$\endgroup\$
1
\$\begingroup\$

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

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

VIM, 37 35 bytes

↵ is the enter key

:h<_↵jjYZZ51P25@='vUlj'↵26@='vUjh'↵
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ nice ::println \$\endgroup\$ – mazzy Jul 25 '18 at 13:35
1
\$\begingroup\$

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?

\$\endgroup\$
  • 1
    \$\begingroup\$ 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. :) \$\endgroup\$ – Kevin Cruijssen Jul 25 '18 at 13:43
0
\$\begingroup\$

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();
        }
        }
}
\$\endgroup\$
  • 6
    \$\begingroup\$ 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. \$\endgroup\$ – Martin Ender Jul 28 '15 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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