69
\$\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\$
5
  • 1
    \$\begingroup\$ Is it safe to assume input is never upper case? \$\endgroup\$
    – Winny
    Jul 26 '15 at 5:46
  • 42
    \$\begingroup\$ @Winny There is no input. The output is fixed. In fact, that's the general idea of kolmogorov-complexity questions. \$\endgroup\$ 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\$ Aug 11 '17 at 22:48
  • \$\begingroup\$ Franck Dernoncourt's point still stands. The link is broken. \$\endgroup\$ Jul 25 '18 at 20:18

83 Answers 83

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

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.

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

jq -nr, 77 72 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!

Some comments:

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

\$\endgroup\$
1
  • \$\begingroup\$ Nice! Unfortunately, I can't award a +50 bounty for this as I've already answered this. \$\endgroup\$
    – emanresu A
    Sep 4 at 10:42
2
\$\begingroup\$

q (37 characters)

A first cut

@[.Q.a;;upper]'[(raze(|:\)til 26)_26]
\$\endgroup\$
1
  • 1
    \$\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\$
    – mkst
    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\$
0
2
\$\begingroup\$

K5, 47 bytes

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

More golfing to come shortly.

\$\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\$

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;}
\$\endgroup\$
4
  • \$\begingroup\$ Can you remove the space after A(i)? I program Java, but it seems like you could. \$\endgroup\$
    – MCMastery
    Jul 29 '15 at 15:47
  • \$\begingroup\$ @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.) \$\endgroup\$
    – Alex A.
    Jul 31 '15 at 16:35
  • \$\begingroup\$ @AlexA. Yes, that's right. The preprocessor needs the space to delimit the macro name from its definition. \$\endgroup\$ Jul 31 '15 at 21:33
  • \$\begingroup\$ 106 bytes \$\endgroup\$
    – ceilingcat
    Mar 9 '20 at 7:37
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\$

><>, 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\$
3
  • \$\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\$
4
  • \$\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\$ 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\$ 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\$
2
  • 2
    \$\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\$ 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\$
3
  • \$\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\$ 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\$
3
  • \$\begingroup\$ Came up with a(longer) different version: Z\z┌l;┐*;n \$\endgroup\$
    – Razetime
    Oct 31 '20 at 15:59
  • \$\begingroup\$ @Razetime that doesn't do the vertical palendromizing. And you could've done ‾¶ instead of ┌l;┐ \$\endgroup\$
    – dzaima
    Nov 1 '20 at 9:35
  • \$\begingroup\$ works, but not palidromized \$\endgroup\$
    – Razetime
    Nov 1 '20 at 9:40
2
\$\begingroup\$

VIM, 37 35 bytes

↵ is the enter key

:h<_↵jjYZZ51P25@='vUlj'↵26@='vUjh'↵
\$\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\$
7
  • \$\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\$ 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 '19 at 10:54
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\$
7
  • \$\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\$ 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
2
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$ Jan 10 at 7:56
  • \$\begingroup\$ @cairdcoinheringaahing thank you for the feedback, I'll check out the tips too! \$\endgroup\$
    – farawi
    Jan 10 at 14:49
2
\$\begingroup\$

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

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.

\$\endgroup\$
3
  • \$\begingroup\$ 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 \$\endgroup\$
    – ovs
    Sep 4 at 8:30
  • \$\begingroup\$ i'm not perfect sure how manatwork's answer works myself. i will tell you if i manage to get it right \$\endgroup\$
    – Razetime
    Sep 4 at 8:49
  • \$\begingroup\$ @ovs got it working! \$\endgroup\$
    – Razetime
    Sep 4 at 8:51
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\$

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\$

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\$

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\$

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.