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

0
\$\begingroup\$

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)

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

Python 3, 103 characters

a="abcdefghijklmnopqrstuvwxyz"
for i in range(51):
 x=25-abs(25-i)
 print(a.replace(a[x],a[x].upper()))
\$\endgroup\$
  • \$\begingroup\$ 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.) \$\endgroup\$ – manatwork Feb 9 '16 at 17:39
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – manatwork Feb 9 '16 at 17:55
  • \$\begingroup\$ manatwork, thanks for all the advice, i was taking the size displayed at the file system, instead of the character count. \$\endgroup\$ – Argenis García Feb 9 '16 at 19:54
0
\$\begingroup\$

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

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.

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

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:]
\$\endgroup\$
  • \$\begingroup\$ the diagonals go forwards & back in the output. You're only outputting half of the required output. \$\endgroup\$ – dzaima Jun 7 '18 at 19:29
  • \$\begingroup\$ Oh, My bad. Ill edit it \$\endgroup\$ – Khalil Jun 8 '18 at 15:59
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

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

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!

\$\endgroup\$
0
\$\begingroup\$

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

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

Japt -R, 11 bytes

;C£ChYXu̐

Test it

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