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.
-
40\$\begingroup\$ Seriously, another alphabet challenge? \$\endgroup\$Nathan Merrill– Nathan Merrill2016年08月09日 23:33:12 +00:00Commented Aug 9, 2016 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– Conor O'Brien2016年08月09日 23:34:07 +00:00Commented Aug 9, 2016 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– Dennis2016年08月09日 23:35:42 +00:00Commented Aug 9, 2016 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– Nathan Merrill2016年08月09日 23:40:33 +00:00Commented Aug 9, 2016 at 23:40
-
16\$\begingroup\$ It's clear there's no more demand for alphabet challenges - only 39 people answered in the first 15 hours... \$\endgroup\$trichoplax is on Codidact now– trichoplax is on Codidact now2016年08月10日 15:23:58 +00:00Commented Aug 10, 2016 at 15:23
99 Answers 99
RETURN, 23 bytes
'A'[␊'B'[␊'A␈13␋␄'␊°␇␂,
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.
-
\$\begingroup\$ A language using
␊instead of a literal newline is weird... \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年09月30日 16:01:49 +00:00Commented Sep 30, 2016 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– Mama Fun Roll2016年10月01日 13:57:12 +00:00Commented Oct 1, 2016 at 13:57
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();}
-
\$\begingroup\$ If you add A at the end of the alphabet you can change
(i+1)%26toi+1\$\endgroup\$Emigna– Emigna2016年08月10日 14:49:06 +00:00Commented Aug 10, 2016 at 14:49 -
\$\begingroup\$ The alphabet can also be
varand you don't need the.ToCharArray()as a string is already just that. \$\endgroup\$Emigna– Emigna2016年08月10日 14:53:57 +00:00Commented Aug 10, 2016 at 14:53 -
\$\begingroup\$ Oh, thank you! This was my first time code golfing, so I'm happy to learn more. \$\endgroup\$aphariel– aphariel2016年08月10日 14:56:24 +00:00Commented Aug 10, 2016 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– Emigna2016年08月10日 15:08:23 +00:00Commented Aug 10, 2016 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– Jamie Rees2016年08月10日 15:42:19 +00:00Commented Aug 10, 2016 at 15:42
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"))
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
Perl 6, 50 bytes
say .join x 13 for flat('A'..'Z','A').rotor(2=>-1)
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 Using a count up loop for (26-n)%26 == (-n)%26, this is not true for C, otherwise these two bytes can be shaved off. (削除ここまで)i resolves the problem
-
\$\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– user541872016年08月10日 08:33:51 +00:00Commented Aug 10, 2016 at 8:33 -
\$\begingroup\$ Use
puts("")instead ofprintf("\n")for printing a newline. \$\endgroup\$owacoder– owacoder2016年08月10日 12:30:56 +00:00Commented Aug 10, 2016 at 12:30 -
\$\begingroup\$ @Advancid no you can't. that
i%95does not work \$\endgroup\$Karl Napf– Karl Napf2016年08月10日 15:39:37 +00:00Commented Aug 10, 2016 at 15:39 -
\$\begingroup\$ @owacoder Ah, good old
puts. Only hadputcharin mind. \$\endgroup\$Karl Napf– Karl Napf2016年08月10日 15:40:40 +00:00Commented Aug 10, 2016 at 15:40
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));}}
-
1\$\begingroup\$ chaning
j==26toj>25allow 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– user9023832016年08月10日 15:25:22 +00:00Commented Aug 10, 2016 at 15:25
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).
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";
-
\$\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– insertusernamehere2016年08月10日 19:09:18 +00:00Commented Aug 10, 2016 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– insertusernamehere2016年08月10日 19:20:16 +00:00Commented Aug 10, 2016 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– Wes2016年08月10日 20:08:48 +00:00Commented Aug 10, 2016 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 constantwhich is fine here. But be careful, this won't work on strings with whitespaces or special characters etc. \$\endgroup\$insertusernamehere– insertusernamehere2016年08月10日 20:21:48 +00:00Commented Aug 10, 2016 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– Wes2016年08月10日 20:25:03 +00:00Commented Aug 10, 2016 at 20:25
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]
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.
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);
-
\$\begingroup\$
console.log=>alert. \$\endgroup\$NoOneIsHere– NoOneIsHere2016年08月10日 21:27:40 +00:00Commented Aug 10, 2016 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– ajxs2016年08月10日 22:08:59 +00:00Commented Aug 10, 2016 at 22:08
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.
-
\$\begingroup\$ You can remove the soace before
b=65. \$\endgroup\$NoOneIsHere– NoOneIsHere2016年08月11日 03:11:57 +00:00Commented Aug 11, 2016 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\$AvahW– AvahW2016年08月11日 03:16:17 +00:00Commented Aug 11, 2016 at 3:16
-
\$\begingroup\$ If you switch to python 2, you can replace
print()withprint, andprint(...,end='')toprint ...,(trailing comma). \$\endgroup\$NoOneIsHere– NoOneIsHere2016年08月11日 03:21:45 +00:00Commented Aug 11, 2016 at 3:21
Scala, 64 bytes
Can anyone improve on this?
(('A'to'Z'):+'A').sliding(2).map(_.mkString*13).foreach(println)
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)
Vitsy, 29 bytes
So, instead of doing the typical thing, I used my two-dimensional stacking to generate the alphabets and then offset them by one from each other, alternating back and forth between them.
9a*d5*Hd\[:{:}]Y?y\[y\[O?]aO]
9a*d5*H Push an alphabet to the stack.
9a* Push 90 to the stack (character code 'Z')
d5* Push 65 to the stack (character code 'A')
H Pop a, b, push range (a, b)
d\[:{:}] Establish the other stacks, while alternating.
d\[ ] Do the bracketed code 13 times.
: : Clone the stack.
{ Put the top item of the stack on the bottom.
} Put the bottom item of the stack on the top.
Y Discard a stack. (13*2+1-1 = 26)
? Rotate right a stack (we start on 'A' now)
y\[y\[O?]aO] Output.
y\[ ] Repeat the code in brackets number of stacks times (26).
y\[ ] Repeat the code in brackets number of stack times (26).
O Pop a, print a as a character.
? Go right a stack.
aO Output a newline.
PHP, (削除) 70 (削除ここまで) (削除) 66 (削除ここまで) 64 Bytes
<?$a=A;$b=B;while($a!=AA)echo str_repeat($a++.($b++)[0],13)."
";
3 bytes short (if I would remove the <? as well) from @insertusernamehere answer. So close!
EDIT:
Actually got it to 66 bytes (64 without the <?)! Doing A and B without quotes actually seem to work. Seems to be the shortest PHP one as time of write :D
EDIT 2: Also removed " " from AA. Still seems to be working.
Bash, (削除) 149 (削除ここまで), (削除) 115 (削除ここまで), (削除) 111 (削除ここまで), 106 bytes
for i in {0..25};{
printf $(printf %b%b \\`printf %o $[i+65]` \\`printf %o $[-~i%26+65]`)%.s {a..m};echo
}
(thanks @manatwork, saved (削除) 34 (削除ここまで), 4 more bytes)
Bash, 140 bytes
(thanks @steeldriver)
for i in {0..25}; do printf "$(printf '%b%b' \\$(printf '%03o' $((i+65))) \\$(printf '%03o' $((-~i%26+65))))%.0s" {1..13}; printf \\n; done
Save to <file> and run as: /bin/bash <file>
-
1\$\begingroup\$
$((...))→$[...],'%b%b'→%b%b,printf \\n→echo, inner$(...)→`...`,do ... done→{ ... },%.0s→%.s,{1..13}→{a..m}. (Some of those you may find in Tips for golfing in Bash.) \$\endgroup\$manatwork– manatwork2016年08月22日 12:30:10 +00:00Commented Aug 22, 2016 at 12:30 -
\$\begingroup\$ Sorry, but
{and}need separators around them. But there are still single quotes to remove aroundprintf's format strings and what I forgot earlier, no need for the double quotes either. pastebin.com/s1h75e5i \$\endgroup\$manatwork– manatwork2016年08月22日 14:42:48 +00:00Commented Aug 22, 2016 at 14:42 -
1\$\begingroup\$ One more thing: 65..90 in octal is 101..132, so they take 3 digits anyway, so
%03o→%o. \$\endgroup\$manatwork– manatwork2016年08月22日 14:55:15 +00:00Commented Aug 22, 2016 at 14:55 -
\$\begingroup\$ Sorry, seems I not explained the error well enough. As the code you posted failed with "line 1: syntax error near unexpected token `{printf'", I edited it. Feel free to revert if you disagree. \$\endgroup\$manatwork– manatwork2016年08月22日 15:38:59 +00:00Commented Aug 22, 2016 at 15:38
-
\$\begingroup\$ @manatwork copy-paste error on my part, thanks (-: \$\endgroup\$KM.– KM.2016年08月22日 17:44:27 +00:00Commented Aug 22, 2016 at 17:44
GNU sed, 95 bytes
s,^,@@@@@@@@@@@@@,;s,@,AB,g
:;p
y,ABCDEFGHIJKLMNOPQRSTUVWXYZ,BCDEFGHIJKLMNOPQRSTUVWXYZA,
/^Z/!b
I wish the 'y' command had this syntax: y,A-Z,B-ZA,.
JavaScript, Z (90) bytes
for(i=65,b=66;i<91;++i,b=b<90?++b:65)console.log(Array(14).join(String.fromCharCode(i,b)))
To learn:
var start = 65,
end = 90;
for (var i = start, b = i+1; i <= end; ++i) {
var chars = String.fromCharCode(i, b);
/* repeat chars 14 times */
console.log(Array(14).join(chars));
}
-
\$\begingroup\$ What is that Z? \$\endgroup\$Erik the Outgolfer– Erik the Outgolfer2016年09月30日 16:03:01 +00:00Commented Sep 30, 2016 at 16:03
-
\$\begingroup\$ @EriktheGolfer You know, Z in ASCII is 90 bytes (\x5a) \$\endgroup\$user48510– user485102016年09月30日 16:42:46 +00:00Commented Sep 30, 2016 at 16:42
Python, 56
for k in range(26):print(chr(k+65)+chr((k+1)%26+65))*13
-
\$\begingroup\$ Ah, I had a look at your answer, @Karl Napf. You used a sneaky method of golfing two bits away from my solution. Thank you for teaching me something new :] \$\endgroup\$NeRoboto– NeRoboto2016年11月11日 13:42:36 +00:00Commented Nov 11, 2016 at 13:42
PHP, 52 bytes
for($a=A;$a!=AA;)echo str_pad("\n",27,$a++.$a[0],0);
Can JavaScript beat this? Run with -r.
Windows batch, 155 bytes
@set s=ABCDEFGHIJKLMNOPQRSTUVWXYZA
@set/ac=-1
:L
@set/ac+=1
@call set t=%%s:~%c%,2%%
@for /l %%i in (1,1,13) do @cd|set/p=%t%
@echo(
@if %t% neq ZA @goto l
Javascript, 98 Bytes
for(var j=371,s="";j<1333;j+=37){for(i=0;i<13;i++)s+=j.toString(36).replace("100","za");s+="<br>"}
-
1\$\begingroup\$ Is that a typo? This doesn't look like 12 bytes to me. (I think it's 98 bytes.) \$\endgroup\$Mitchell Spector– Mitchell Spector2017年02月17日 04:02:36 +00:00Commented Feb 17, 2017 at 4:02
Pyth, 12 bytes
I haven't been there
VG*13+N@G=hZ
Explanation:
VG In the lowercase alphabet...
*13 13 times...
+N@G=hZ The current item concatenated with alphabet[++Z]
K (oK), 23 bytes
Solution:
`c65ドル+26#'a,'1_27#a:!26
Explanation:
`c65ドル+26#'a,'1_27#a:!26 / solution
!26 / range 0..25
a: / save as 'a'
27# / 27 take, wraps to make ABC...XYZA
1_ / 1 drop, take off leading A
a,' / concatenate each element with each of a (AB,BC,etc)
26#' / 26 take each, wraps to get ABABAB... BCBCBC... etc
65+ / add 65, vectorised (65=A in ASCII)
`c$ / cast to characters
Bonus:
Here are a couple of other ways to get the result:
24 chars: Try it online!
`c65ドル++26#(!26;1_27#!26)
27 chars: Try it online!
26#'+0 1_'26 27#\:`c65ドル+!26
q/kdb+, 19 bytes
Solution:
26#'.Q.A,'1_27#.Q.A
Explanation:
Shorter and different to my oK solutions as we have a shortcut to the uppercase alphabet by means of .Q.A. As always, interpreted right-to-left
26#'.Q.A,'1_27#.Q.A / solution
.Q.A / shortcut to uppercase alphabet, ABC..XYZ
27# / 27 take, wraps to get ABC...XYZA
1_ / 1 drop, drop first element to give BCD...XYZA
.Q.A,' / concatenate each left/right lists, so AB, BC, CD etc
26#' / 26 take each, gives ABABA.. BCBCB... etc
Mathematica, 52 bytes
Column[""<>#~Table~13&/@Partition[Alphabet[],2,1,1]]
-1 byte from Martin Ender
-
\$\begingroup\$ Infix notation for
Tablesaves a byte. \$\endgroup\$Martin Ender– Martin Ender2017年11月30日 14:41:19 +00:00Commented Nov 30, 2017 at 14:41
Explore related questions
See similar questions with these tags.