36
\$\begingroup\$

You are to print this exact text:

ABABABABABABABABABABABABAB
BCBCBCBCBCBCBCBCBCBCBCBCBC
CDCDCDCDCDCDCDCDCDCDCDCDCD
DEDEDEDEDEDEDEDEDEDEDEDEDE
EFEFEFEFEFEFEFEFEFEFEFEFEF
FGFGFGFGFGFGFGFGFGFGFGFGFG
GHGHGHGHGHGHGHGHGHGHGHGHGH
HIHIHIHIHIHIHIHIHIHIHIHIHI
IJIJIJIJIJIJIJIJIJIJIJIJIJ
JKJKJKJKJKJKJKJKJKJKJKJKJK
KLKLKLKLKLKLKLKLKLKLKLKLKL
LMLMLMLMLMLMLMLMLMLMLMLMLM
MNMNMNMNMNMNMNMNMNMNMNMNMN
NONONONONONONONONONONONONO
OPOPOPOPOPOPOPOPOPOPOPOPOP
PQPQPQPQPQPQPQPQPQPQPQPQPQ
QRQRQRQRQRQRQRQRQRQRQRQRQR
RSRSRSRSRSRSRSRSRSRSRSRSRS
STSTSTSTSTSTSTSTSTSTSTSTST
TUTUTUTUTUTUTUTUTUTUTUTUTU
UVUVUVUVUVUVUVUVUVUVUVUVUV
VWVWVWVWVWVWVWVWVWVWVWVWVW
WXWXWXWXWXWXWXWXWXWXWXWXWX
XYXYXYXYXYXYXYXYXYXYXYXYXY
YZYZYZYZYZYZYZYZYZYZYZYZYZ
ZAZAZAZAZAZAZAZAZAZAZAZAZA

Specs

  • You can print all lowercase instead of all uppercase. However, case must be consistent throughout the output.
  • You may print one extra trailing linefeed.

Scoring

Since this is an alphabet wave that fluctuates to a small extent, your code should also be small in terms of byte-count. In fact, the smallest code in terms of byte-count wins.

\$\endgroup\$
  • 39
    \$\begingroup\$ Seriously, another alphabet challenge? \$\endgroup\$ – Nathan Merrill Aug 9 '16 at 23:33
  • 6
    \$\begingroup\$ @NathanMerrill As numerous as they are, I don't think they are worthy of downvotes. (I do not imply you downvoted, I am merely saying.) \$\endgroup\$ – Conor O'Brien Aug 9 '16 at 23:34
  • 14
    \$\begingroup\$ As long as the patterns are sufficiently different, I don't think it matters if we use the alphabet, decimal digits, asterisks and underscore, etc. \$\endgroup\$ – Dennis Aug 9 '16 at 23:35
  • 9
    \$\begingroup\$ @Dennis regardless of the characters used, its these type of "pattern" challenges that are getting overused, IMO. I don't think its offtopic, but I would enjoy some fresh air. \$\endgroup\$ – Nathan Merrill Aug 9 '16 at 23:40
  • 11
    \$\begingroup\$ It's clear there's no more demand for alphabet challenges - only 39 people answered in the first 15 hours... \$\endgroup\$ – trichoplax Aug 10 '16 at 15:23

83 Answers 83

1
\$\begingroup\$

PHP, 65 bytes

Well, this is pretty straight forward:

for(;$i<26;)echo str_repeat(chr(65+$i).chr(65+(++$i%26)),13)."
";
\$\endgroup\$
1
\$\begingroup\$

Oracle SQL 11.2, 141 138 bytes

SELECT LISTAGG(CHR(l+64)||CHR(MOD(l,26)+65))WITHIN GROUP(ORDER BY l)FROM(SELECT CEIL(LEVEL/13)l FROM DUAL CONNECT BY LEVEL<339)GROUP BY l;

Un-golfed

SELECT LISTAGG(CHR(l+64)||CHR(MOD(l,26)+65))WITHIN GROUP(ORDER BY l)
FROM   (
         SELECT CEIL(LEVEL/13)l 
         FROM   DUAL 
         CONNECT BY LEVEL<339  -- 26*13+1
       )
GROUP BY l                               
\$\endgroup\$
1
\$\begingroup\$

C#, 107 bytes

My first attempt at a submission to PPCG

Golfed:

var l="";int i=0,j=0;for(;i<26;i++){for(;j<26;j++)l+=(char)(((j%2)+i)%26+65);Console.WriteLine(l);l="";j=0;}

Ungolfed:

var l="";
int i=0,j=0;
for(;i<26;i++){
    for(;j<26;j++)l+=(char)(((j%2)+i)%26+65);
        Console.WriteLine(l);
    l="";j=0;
}

Pretty sure this adheres to standards! Would love to hear any potential improvements.

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

JavaScript (ES6), 88 83 bytes

_=>[..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"].map((c,i,a)=>(c+a[-~i%26]).repeat(13)).join`\n`

Where \n represents the literal newline character. Writing the alphabet out saved me three bytes today, but @LeakyNun saved me another five bytes.

\$\endgroup\$
  • 1
    \$\begingroup\$ Did it save you four bytes yesterday? \$\endgroup\$ – Leaky Nun Aug 10 '16 at 0:51
  • 1
    \$\begingroup\$ _=>[...s="ABCDEFGHIJKLMNOPQRSTUVWXYZ"].map((c,i)=>(c+s[-~i%26]).repeat(13)).join`\n` \$\endgroup\$ – Leaky Nun Aug 10 '16 at 0:52
  • \$\begingroup\$ @LeakyNun No, just two, I'm afraid: codegolf.stackexchange.com/a/89297/17602 \$\endgroup\$ – Neil Aug 10 '16 at 7:57
  • 2
    \$\begingroup\$ The (c,i,a) is watching you. \$\endgroup\$ – gcampbell Aug 10 '16 at 8:18
1
\$\begingroup\$

C (86 bytes):

for(int c=-11,n=-26;++n<1;){while(c++){printf("%c%c",90+n,n?91+n:65);}c=-11;puts("");}

My first attempt on a Code Golf challenge.

Some answers are really impressive!

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

Java 7, 87 bytes

void c(){for(int i=0;i<703;)System.out.print((char)(i++%27>0?65+(i/27+i%27%2)%26:10));}

Based on @orlp's amazing answer.

Ungolfed & test code:

Try it here.

class Main {
  public static void main(String[]a){
    c();
  }

  static void c(){
    for(int i=0; i<703;){
        System.out.print((char)(i++%27 > 0
                                  ? 65 + (i/27+i%27%2)%26
                                  :10));
    }
  }
}
\$\endgroup\$
1
\$\begingroup\$

Python 2 53 bytes

i=0;exec'print(chr(i+65)+chr(-~i%26+65))*13;i+=1;'*26
\$\endgroup\$
1
\$\begingroup\$

T-SQL 99 90 bytes

Saved 9 bytes thanks to @t-clausen.dk

DECLARE @ INT=65z:PRINT REPLICATE(CHAR(@)+CHAR(IIF(@=90,65,@+1)),13)SET @+=1IF @<=90GOTO z

Ungolfed:

DECLARE @CurrCharacter INT = 65; --ASCII decimal for 'A'
WHILE (@CurrCharacter <=90) --ASCII decimal for 'Z'
BEGIN 
   PRINT REPLICATE(
    REPLACE(CHAR(@CurrCharacter)+CHAR(@CurrCharacter+1),'[','A')
    ,13); --Replicate the current character and its neighbor 13 times. If the neighbor is '[' (ASCII code 91) then replace it with 'A'.
   SET @CurrCharacter+=1; --Go to the next letter
END
\$\endgroup\$
  • \$\begingroup\$ That is very nice, you can save another 9 bytes like this \$\endgroup\$ – t-clausen.dk Aug 29 '16 at 9:16
1
\$\begingroup\$

Common Lisp, SBCL, 86 bytes

(dotimes(i 26)(format t"~13@{~a~:*~}~%"(subseq"ABCDEFGHIJKLMNOPQRSTUVWXYZA"i(+ i 2))))

Explanation

(dotimes(i 26);loop from i=0 to i=25
(format t"~13@{~a~:*~}~%"(subseq"ABCDEFGHIJKLMNOPQRSTUVWXYZA"i(+ i 2))))
;print 13 times pairs of "AB", "BC", ... , "ZA"
\$\endgroup\$
1
\$\begingroup\$

SOGL V0.12, 8 bytes

Z«Z¹'⁰∙I

Try it Here!

Explanation:

Z         push the uppercase alphabet
 «        put its first letter at the end
  Z       push the alphabet once again
   ¹      wrap in array: ["BCDEFGHIJKLMNOPQRSTUVWXYZA", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"]
    '⁰∙   multiply vertically 13 times
       I  rotate clockwise
\$\endgroup\$
1
\$\begingroup\$

Bash, 64 bytes

f()(tr A-Z B-ZA|tee >(((i++<25))&&f);echo)
printf ZA%.s {a..m}|f

Credit to seshoumara's sed answer for the idea of translating A-Z to B-ZA.

Try it online!

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

c64 basic v2, 95 93 85 83 77 bytes

0fOy=65to90:l$="":a$=cH(y)+cH(y+1+(y=90)*26)
1fOx=0to12:l$=l$+a$:nE:?l$:nE

Screenshot:

enter image description here

Trial instructions are in my previous answer.

\$\endgroup\$
  • \$\begingroup\$ can you switch out 0..25 for 65..90 in the first line? e.g. 0fOy=65to90:l$="":a$=chr$(y):b$=chr$(1+y):ify=90tHb$="a" for -3 bytes? \$\endgroup\$ – streetster Sep 13 '17 at 21:25
  • 1
    \$\begingroup\$ @streetster Thanks! And I switched to conditional operator to avoid the if-then! :-) It is already 85. Screenshot follows. \$\endgroup\$ – peterh Sep 13 '17 at 21:34
0
\$\begingroup\$

Julia, 51 bytes

!()=join(["$x$(x+1-26(x>89))"^13for x='A':'Z'],"
")

Initial golfing.

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

RETURN, 23 bytes

'A'[␊'B'[␊'A␈13␋␄'␊°␇␂,

Try it here.

NOTE: Use the "Insert String" button and paste the above code in.

Explanation

Basically generates A-Z and B-Z and A at the end on the stack. Then the stack is duplicated 13 times, transposed, joined with a newline, and outputted.

Due to a bug that I just can't fix, 'A'[␊${25@}13␋␄'␊°␇␂, does not work.

\$\endgroup\$
  • \$\begingroup\$ A language using instead of a literal newline is weird... \$\endgroup\$ – Erik the Outgolfer Sep 30 '16 at 16:01
  • \$\begingroup\$ No, I'm just putting it there to avoid confusion; newlines are range commands, so having ␊ there emphasizes that. It's the same with the other unprintables. \$\endgroup\$ – Mama Fun Roll Oct 1 '16 at 13:57
0
\$\begingroup\$

Javascript (using external library Enumerable) (84 bytes)

    n=>(w=_.Range(0,26)).WriteLine(x=>w.Write("",y=>String.fromCharCode((x+y%2)%26+65)))

Link to lib: https://github.com/mvegh1/Enumerable/

Code explanation: Create a range of ints starting at 0 for count of 26. Store into global variable w. For each, write a new line according to predicate. Predicate states to take "w" and write a joined string based off the passed predicate to Write. Predicate to Write uses an empty string as the join delimiter, and uses the current integer value from WriteLine ("x") and the current integer value from Write ("y") to calculate the correct string at that position

Edit: Removed extra parens to save 2 bytes

enter image description here

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

Pyke, 13 bytes

GGt\a+]w-*,_X

Try it here!

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

C# - 159 138 bytes

var a="ABCDEFGHIJKLMNOPQRSTUVWXYZA";for(int i=0;i<26;i++){for(int j=0;j<14;j++){Console.Write("{0}{1}",a[i],a[i+1]);}Console.WriteLine();}
\$\endgroup\$
  • \$\begingroup\$ If you add A at the end of the alphabet you can change (i+1)%26 to i+1 \$\endgroup\$ – Emigna Aug 10 '16 at 14:49
  • \$\begingroup\$ The alphabet can also be var and you don't need the .ToCharArray() as a string is already just that. \$\endgroup\$ – Emigna Aug 10 '16 at 14:53
  • \$\begingroup\$ Oh, thank you! This was my first time code golfing, so I'm happy to learn more. \$\endgroup\$ – aphariel Aug 10 '16 at 14:56
  • \$\begingroup\$ Creating the row in a variable and replacing the inner for with a while saves at least 13 additional bytes. \$\endgroup\$ – Emigna Aug 10 '16 at 15:08
  • \$\begingroup\$ You can save a few bytes by using string interpolation like this: Console.Write($"{a[i]}{a[i+1]}") which makes it 135 bytes \$\endgroup\$ – Jamie Rees Aug 10 '16 at 15:42
0
\$\begingroup\$

JAVA 9, 103 97 bytes

it works on JShell, provided by Java9 SDK.

for(int c=64,i;++c<91;)for(i=0;i<26;)System.out.print((char)((c-13+i%2)%26+65)+(i++<25?"":"\n"))
\$\endgroup\$
0
\$\begingroup\$

ListSharp, 236 bytes

ROWS x=ROWSPLIT "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,T,S,U,V,W,X,Y,Z,A" BY [","]
[FOREACH NUMB IN 1 TO 26 AS i]
{
STRG t =""
[FOREACH NUMB IN 1 TO 13 AS j]
{
STRG e=GETLINE x [i]
STRG r=GETLINE x [i+1]
STRG t=t+e+r
}
ROWS s=s+t
}
SHOW=s

Feel free to comment if you want anything to be explained to you

Execution screenshot: Execution screenshot

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

Perl 6, 50 bytes

say .join x 13 for flat('A'..'Z','A').rotor(2=>-1)
\$\endgroup\$
0
\$\begingroup\$

C, 77 74 71 bytes

Basically the same as the Python answer inspired by LeakyNun, Thanks to owacoder for puts :

f(i,j){for(i=0;++i<27;puts(""))for(j=13;--j;printf("%c%c",i+64,i%26+65));}

Usage:

f();

While mathematically (26-n)%26 == (-n)%26, this is not true for C, otherwise these two bytes can be shaved off. Using a count up loop for i resolves the problem

\$\endgroup\$
  • \$\begingroup\$ You can save two bytes by counting from 64: f(i,j){for(i=64;++i<91;printf("\n"))for(j=13;--j;printf("%c%c",i,i%91+65));} \$\endgroup\$ – user54187 Aug 10 '16 at 8:33
  • \$\begingroup\$ Use puts("") instead of printf("\n") for printing a newline. \$\endgroup\$ – owacoder Aug 10 '16 at 12:30
  • \$\begingroup\$ @Advancid no you can't. that i%95 does not work \$\endgroup\$ – Karl Napf Aug 10 '16 at 15:39
  • \$\begingroup\$ @owacoder Ah, good old puts. Only had putchar in mind. \$\endgroup\$ – Karl Napf Aug 10 '16 at 15:40
0
\$\begingroup\$

Java 8, 139 137 bytes

()->{for(int i=65,j=1;;j++){if(j>25){j=++i<91?1:0;System.out.println();
if(j==0)break;}System.out.print((char)i+""+(char)(i>89?65:i+1));}}
\$\endgroup\$
  • 1
    \$\begingroup\$ chaning j==26 to j>25 allow you to save 1 byte. using multiple print statements when you are golfing in java cost you badly, and you could refactor it to use single print statement \$\endgroup\$ – user902383 Aug 10 '16 at 15:25
0
\$\begingroup\$

EXCEL: 53 bytes

=REPT(CHAR(ROW(A1)+64)&CHAR(MOD(ROW(A1),26)+65),13)

Place in A1 and drag to desired length of wave (in this case, 26, one cell for each letter).

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

Improving on @gabe3886's answer (new account and not able to comment)

PHP 94 92 Bytes

<?php for($i=0;$i<26;)echo str_repeat(substr('ABCDEFGHIJKLMNOPQRSTUVWXYZA',$i++,2),13)."\n";

However if you suppress notices, it's 92 90 bytes

<?php for(;@$i<26;)echo str_repeat(substr('ABCDEFGHIJKLMNOPQRSTUVWXYZA',@$i++,2),13)."\n";
\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG. You can golf this down to 79 bytes: for(;$i<26;)echo str_repeat(substr(ABCDEFGHIJKLMNOPQRSTUVWXYZA,$i++,2),13)."↵";. Replace with an actual line break. As an additional note: You don't need to include the PHP opening tag and you don't need to handle notices. \$\endgroup\$ – insertusernamehere Aug 10 '16 at 19:09
  • \$\begingroup\$ You can even save another 6 bytes, with a total of 73 bytes: for(;$i<26;)echo str_repeat(substr(implode(range(A,Z)).A,$i++,2),13)."↵"; \$\endgroup\$ – insertusernamehere Aug 10 '16 at 19:20
  • \$\begingroup\$ @insertusernamehere: Thanks! I wasn't too clear on the rules for this exchange (IE: does it include just functional code (no <?php tag) and/or would warnings be considered part of the output). I noticed in your second comment that range(A,Z) don't have the A and Z characters quoted. Is that abusing another PHP "feature"? \$\endgroup\$ – Wes Aug 10 '16 at 20:08
  • \$\begingroup\$ Yes, I've removed the quotes in both suggestions. When you run a string without quotes it should prompt something like Notice: Use of undefined constant which is fine here. But be careful, this won't work on strings with whitespaces or special characters etc. \$\endgroup\$ – insertusernamehere Aug 10 '16 at 20:21
  • \$\begingroup\$ Right. I remember now. PHP will assume it's the literal character "A"(or "Z" or whatever), which is the same reason "foo $bar[baz]" interpolation works without the curly braces. \$\endgroup\$ – Wes Aug 10 '16 at 20:25
0
\$\begingroup\$

Logo, 93 bytes

Here's a non-graphical Logo solution. Try it online with Calormen.com's interpreter.

to m:c type char 65+modulo:c 26end
to b:a repeat 13[m:a-1 m:a] pr" end
repeat 26[b repcount]
\$\endgroup\$
0
\$\begingroup\$

VIM, 42

:h<_↵↵↵YZZP:s/./&\r/g↵^25↑y↑pG2↑aa↓^ggy13P

where:

  • is return,
  • ^ is ctrl + v
  • ↑ is the up arrow
  • ↓ is escape

I'm sure this can be golfed more. I'm new to VIM so any suggestions are appreciated.

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

Javascript(ES5), 107 99 bytes

for(var s="",i=-1;++i<676;)i&&!(i%26)&&(s+="\n"),s+=String.fromCharCode((i/26+i%2)%26+65);alert(s);
\$\endgroup\$
  • \$\begingroup\$ console.log => alert. \$\endgroup\$ – NoOneIsHere Aug 10 '16 at 21:27
  • \$\begingroup\$ Thanks for pointing that out! Made another small change as well. This is the part I'd really like to change "i&&!(i%26)", surely there's a better way of doing both checks here at once, or at least in a more concise way! I'd love any suggestions here! \$\endgroup\$ – ajxs Aug 10 '16 at 22:08
0
\$\begingroup\$

python 3, 92 90 bytes

a=65
b=66
for i in range(312):
    if a>89:b=65
    print(chr(a)+chr(b),end="")
    if (i+1)%12<1:
        a+=1
        b+=1
        print()

python 2, 80 bytes

a=65
b=66
for i in range(312):
    if a>89:b=65
    print chr(a)+chr(b),
    if (i+1)%12<1:
        a+=1
        b+=1
        print

This program outputs AB AB AB AB... rather than ABABABAB... I'm not sure if this is allowed, but it's the best I can come up with.

EDIT:

Thanks @User902383 for you comment on @TAsk's post allowing me to shave off 2 bytes.

And thanks @NoOneIsHere for suggesting that I move to python 2 instead of 3, I've included a second program in python 2 with a new byte count.

\$\endgroup\$
  • \$\begingroup\$ You can remove the soace before b=65. \$\endgroup\$ – NoOneIsHere Aug 11 '16 at 3:11
  • \$\begingroup\$ Thanks, I think I already had mentally omitted that when I counted it, just not taken it out of the code. Thanks anyway though. \$\endgroup\$ – sonrad10 Aug 11 '16 at 3:16
  • \$\begingroup\$ If you switch to python 2, you can replace print() with print, and print(...,end='') to print ..., (trailing comma). \$\endgroup\$ – NoOneIsHere Aug 11 '16 at 3:21
0
\$\begingroup\$

Scala, 64 bytes

Can anyone improve on this?

(('A'to'Z'):+'A').sliding(2).map(_.mkString*13).foreach(println)
\$\endgroup\$
0
\$\begingroup\$

Python 2.7, 65 bytes

Python 2 alternative using a recursive function

def l(a=0):
 print(chr(a+65)+chr(-~a%26+65))*13
 if a<25:l(-~a)
\$\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.