Imprimer une vague d'alphabet

37

Vous devez imprimer ce texte exact:

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

Spécifications

  • Vous pouvez imprimer toutes les minuscules au lieu de toutes les majuscules. Cependant, la casse doit être cohérente tout au long de la sortie.
  • Vous pouvez imprimer un saut de ligne supplémentaire.

Notation

Dans la mesure où il s’agit d’une vague d’alphabet qui fluctue légèrement, votre code doit également être petit en termes de nombre d’octets. En fait, le plus petit code en termes de nombre d'octets gagne.

Fuite Nun
la source
39
Sérieusement, un autre défi de l'alphabet?
Nathan Merrill
6
@NathanMerrill Aussi nombreux qu'ils soient, je ne pense pas qu'ils méritent d'être rejetés. (Je ne vous implique pas, je dis simplement.)
Conor O'Brien
14
Tant que les motifs sont suffisamment différents, je ne pense pas que le fait que nous utilisions l'alphabet, les chiffres décimaux, les astérisques et les caractères de soulignement, etc. importe peu.
Dennis
9
@Dennis, quels que soient les personnages utilisés, c’est ce type de "motif" qui devient trop utilisé, OMI. Je ne pense pas que ce soit hors-sujet, mais je voudrais profiter d'un peu d'air frais.
Nathan Merrill
13
Il est clair qu'il n'y a plus de demande pour des défis en alphabet - 39 personnes seulement ont répondu dans les 15 premières heures ...
trichoplax

Réponses:

37

C, 60 octets

main(i){for(;i<703;)putchar(i++%27?65+(i/27+i%27%2)%26:10);}
orlp
la source
10
C'est du génie.
Leaky Nun
C'est bien de voir C dans un défi de golf.
Micheal Johnson
@ MichealJohnson " voir C ", IC ce que vous avez fait là-bas. ;) Et je suis d'accord avec Leaky Nun . Parfois, je me demande comment les gens trouvent certaines de ces réponses ingénieuses.
Kevin Cruijssen
@KevinCruijssen C'était involontaire lol.
Micheal Johnson
17

Brainfuck, 104 octets

>+[+[<]>>+<+]><<+++++[>+++++>>++<<<-]>[-<+++++++++++++[->>.+.-<<]>>>.<+<]<----[>+<----]>++>>+++[-<.<.>>]
orlp
la source
1
Pratiquement la même taille que Hello World. Impressionnant!
phyrfox
3
@phyrfox En fait ...
Sp3000
14

Convexe, 10 octets

U_(+]D*zN*

Essayez-le en ligne!

U               Predefined Variable: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
 _(+            Push a copy with the 'A at the end.
    ]           Add both strings to an array.
     D*         Repeat array 13 times. D defaults to 13.
       z        Transpose.
        N*      Join by newlines. N defaults to "\n"
GamrCorps
la source
9

Pyth, 11 à 10 octets

jC*13.<BG1

Essayez ici.

        G   the alphabet
       B    bifurcate over
     .<  1  left shift by 1
  *13       repeat 13 times
 C          transpose
j           join on newlines
Poignée de porte
la source
8

Vim, 85 83 octets

:h<_<cr><cr><cr>YZZP:s/./\0\r/g<cr><c+v>ggy25Pqqlxj:let @a='xkPjj'<cr>25@akia<esc>25klq11@qh<ctrl+v>25jylpl<c+v>25jdGdd

Je sais que cela peut être joué davantage au golf, mais ma tête me fait mal alors je dois m'arrêter pour le moment.

<cr> est la touche entrée, <c+v> ctrl + v et <esc>la touche Échap. Ceux-ci ont tous été comptés comme un octet.

J'ai enregistré un gif de cela, mais ça a été foiré. La vidéo est bien cependant: http://recordit.co/ldLKvho9Gi

addison
la source
8

Ruby, 42 39 38 37 octets

-3 octets grâce à @ user81655
-1 octet grâce à @manatwork
-1 octet grâce à @NotthatCharles

?A.upto(?Z){|a|puts (a+a.next[0])*13}

Voir sur repl.it: https://repl.it/CmOJ

Jordan
la source
7

Cheddar, 48 octets

print(65|>90).map(l->@"[l,l>89?65:l+1]*13).vfuse

Le cheddar est bon avec des cordes: D

Essayez-le en ligne!

Explication

print
  (65|>90)            // Range from 65 (A) to 90 (Z)
  .map(l->            // Map through range
    @"                // Convert following array of char codes to string
      [l,             // The character 
       l>89?65:l+1]   // See below for explanation
      *13             // Repeat 13 times
  ).vfuse             // Vertically fuse

Que fait l>89?65:l+1-il? Bien 89est le code de caractère pour Y. Fondamentalement, l>89vérifie si la lettre est Z, cela signifie que nous devrions revenir A. Si l>89est faux. Je reviendrai l+1, le prochain personnage

Downgoat
la source
I thought you can insert @" between them.
Leaky Nun
Doesn't this use a function return?
Conor O'Brien
@ConorO'Brien yeah?
Downgoat
@ConorO'Brien oh, didn't see in challenge spec. will fix
Downgoat
7

Jelly, 10 bytes

26ḶḂØAṙZj⁷

Try it online!

How it works

26ḶḂØAṙZj⁷  Main link. No arguments.

26Ḷ         Yield [0, ..., 25].
   Ḃ        Bit; compute the parity of each intger.
    ØAṙ     Rotate the alphabet by these amounts.
       Z    Zip; transpose rows and columns.
        j⁷  Join, separating by linefeeds.
Dennis
la source
Didn't Y exist back then? Also congrats for 100k rep!!
Erik the Outgolfer
Thanks! I checked and, sadly, Y was added two days after the challenge was posted.
Dennis
Because you could have golfed it further down to 26ḶḂØAṙZY. But, as it is right now, it's still good.
Erik the Outgolfer
7

Haskell, 60 58 bytes

mapM putStrLn[[0..12]>>[a,b]|a:b:_<-scanr(:)"A"['A'..'Z']]

Starting with "A" scanr(:) builds the a list from the chars of ['A'..'Z'] from the right. (-> ["ABCDE...A", "BCDEF..A", ..., "XYZA", "YZA", "ZA", "A"]). (a:b:_) matches the first two chars of each sublists (with at least two chars) and makes 13 copies of it.

nimi
la source
Considering some of the cheats used by other languages on a regular basis I consider it only fair to not include the actual printing. In this case you could replace it with "(++"\n")=<<" and save 2 bytes. Possibly more.
MarLinn
@MarLinn: No, I don't think so. Golfing languages are designed with implicit printing in mind and most other answers do have some sort of printing command. Btw, unlines is even shorter than (++"\n")=<<.
nimi
7

PowerShell, 49 43 bytes

TimmyD's remix:

65..89|%{-join[char[]]($_,++$_)*13};"ZA"*13

was, 49 bytes:

0..25|%{(""+[char]($_+++65)+[char]($_%26+65))*13}

Example output

TessellatingHeckler
la source
6

Python 2, 70 68 54 bytes

List based solution:

L=map(chr,range(65,91))
for i in range(-26,0):print(L[i]+L[i+1])*13

But why create a list? Thanks LeakyNun:

for i in range(26):print(chr(i+65)+chr(-~i%26+65))*13
Karl Napf
la source
6

R, 72 67 60 56 bytes

write(matrix(LETTERS[c(1:26,2:26,1)],26,26,T),"",26,,"")

Thanks to @Giuseppe for the extra 4 bytes off!

Old rep-based solution at 60 bytes:

for(i in 1:26)cat(rep(LETTERS[c(i,i%%26+1)],13),"\n",sep="")

See here on an online interpreter. Thanks to @user5957401 for the extra 7 bytes off!

Old matrix-based solution at 72 bytes:

for(i in 1:26)cat(matrix(LETTERS[c(1:26,2:26,1)],26,26)[i,],"\n",sep="")

See here on an online interpreter.

plannapus
la source
1
if you change the indext to i in 1:26 and then the letter selection to LETTERS[c(i,i%%26+1)] you can drop like 6 or 7 bytes
user5957401
1
@user5957401 arf I was so stubbornly doing (i+1)%%26 that it didn't occur to me to do the opposite! Thanks!
plannapus
1
56 bytes using matrices again :)
Giuseppe
5

MATL, 13 bytes

1Y2tn:!to~!+)

Try it online!

1Y2    % Predefined string literal: 'AB···Z'
tn:    % Duplicate, number of elements, range: gives [1, 2, ···, 26]
!      % Transpose into a column vector
to~!   % Duplicate and transform into [0, 1, 0, 1, ···, 1] using modulo 2
+      % Addition with broadcast. Gives 2D numeric array
)      % Index (modularly) into string. Implicitly display.
Luis Mendo
la source
5

Jellyfish, 26 bytes

P
+'A
~
| S
+$ r2
 ,'
r'

Note the trailing unprintable characters on the last two lines. Try it online!

Explanation

This is basically an arithmetic manipulation approach: make a 26×26 grid with alternating 0-1 pattern, add the index of each row to every element of the row, reduce mod 26, and add the ASCII value of A. Characters in Jellyfish are just numbers with a special flag, and all arithmetic works on them as expected.

From bottom to top:

  • The 's are character literals; they are followed by unprintables with ASCII code 26, and stand for those characters.
  • The lower r computes the character range from 0 to 25.
  • The , forms a pair from the two unprintable chars.
  • The higher r is given argument 2, and forms the range [0 1].
  • The $ takes that range, and reshapes it into the shape given by its other argument, which is the pair of unprintables. This gives a 26×26 matrix of alternating rows 0 1 0 1 0 1 ...
  • The lower + adds the char range 0-25 to this matrix. The addition distributes on the rows, so row i is incremented by i. It's also converted to a char matrix, since the south argument consists of chars.
  • The ~| is modulus with flipped arguments: the south argument (the above char matrix) is reduced modulo the east argument (the S turns the argument-seeking process south, so this is the unprintable literal 26).
  • The higher + adds the literal A to every coordinate of the resulting matrix.
  • The P prints the result in matrix format, that is, each row on its own line without quotes.
Zgarb
la source
1
I wanted to try to golf but then I saw the name of him who wrote the code.
Leaky Nun
@LeakyNun You can still try! Although 26 bytes is fitting for this challenge.
Zgarb
5

Vim, 31 bytes

:h<_↵↵↵YZZPJra0qqy2l13Plr↵25@qD

Where is the Return key.

enter image description here

Lynn
la source
5

Perl, 26 bytes

Solution from @Dom Hastings. (12 bytes shorter than mine!)
-1 byte thanks to @Ton Hospel

say+($_++,chop)x13for A..Z

Run with -M5.010 or -E :

perl -E 'say+($_++,chop)x13for A..Z'
Dada
la source
Managed to get this down to 33: say+($_++,$_--=~/^./g)x13for A..Z, but I'm sure there's a way to get a shorter one from: say+($_++,$_--)x13for A..Z...
Dom Hastings
Not sure why I have the -- in there, it's not needed! O_o. 27: say+($_++,/^./g)x13for A..Z
Dom Hastings
@DomHastings Nicely done! I tried say+($_,$_++)x13for A..Z at first which didn't work, but it seems I should have push further into that direction!
Dada
1
say+($_++,chop)x13for A..Z saves one more byte
Ton Hospel
@TonHospel great, thanks for that.
Dada
5

T-SQL 133 Bytes (Golfed by : @t-clausen.dk)

SELECT REPLICATE(Char(number+65)+IIF(number=25,'A',Char(number+66)),13)FROM spt_values WHERE number<26and'P'=TYPE

T-SQL , 151 Bytes

Using CTE to generate sequence of number

;WITH n(a,v) AS(SELECT CHAR(65)+CHAR(66), 66 UNION ALL SELECT CHAR(v)+CHAR(v+1), v+1 FROM n WHERE v < 91)SELECT REPLICATE(REPLACE(a,'[','A'),13) FROM n

T-SQL, 155 Bytes

SELECT REPLICATE(Char(number+65)+ CASE WHEN number=25 THEN 'A' ELSE Char(number+66) END, 13) FROM master.dbo.spt_values  WHERE name IS NULL AND number < 26
Anuj Tripathi
la source
I have golfed your answer down to 113 characters. I provided a very different answer in TSQL
t-clausen.dk
@t-Clausen.dk That is excellent. Please post your answer. I would delete mine.
Anuj Tripathi
no reason to delete your answer, you can just use my fiddle to improve your answer. I already posted 1 hour ago ago, if you enjoy TSQL , you should take a look at my other answers. I made Fiddles for most of them
t-clausen.dk
4

Julia, 46 bytes

[println("$c$(c+1-26(c>89))"^13)for c='A':'Z']

Try it online!

Dennis
la source
4

Pyth, 10 bytes

jCm.<G~!ZG

Demonstration

Explanation:

jCm.<G~!ZG
  m      G    Map over G, predefined to the lowercase alphabet.
              This will give 26 columns.
   .<G        Left shift (cyclically) G by
        Z     Z elements. Z is initialized to 0.
      ~!      After using its value, logical not Z. (0 -> 1, 1 -> 0)
 C            Transpose
j             Join on newlines
isaacg
la source
Nice, wish I knew as much as you do about Pyth
Stan Strum
4

Brainfuck, 88 86 bytes

++[[+>]<+<++]+>-[[->+>+<<]>>-]++++++++[<[++++++++<+<]>[>]<-]<<++<[>+++[->.<<.>]<<++.<]

Requires an interpreter with 8-bit cells and a tape not bounded on the left. Try it online!

Sp3000
la source
3

Lua, 80 65 Bytes.

s = string c = s.char for i=1,26 do print(s.rep(c(64+i)..c((65+(i%26))),13)) end

With help from Leaky Nun

c=("").char for i=1,26 do print((c(64+i)..c(65+i%26)):rep(13))end

Lua is a pretty inefficent language in regards to handling of strings and such, so this is the best I can narrow it down.

ATaco
la source
Welcome to PPCG! Nice first post! You can save 5 bytes if you remove some unnecessary whitespace: s=string c=s.char for i=1,26 do print(s.rep(c(64+i)..c((65+(i%26))),13))end
GamrCorps
for i=1,26 do print(((64+i):char()..(65+(i%26)):char()):rep(13))end (not tested)
Leaky Nun
Because string.rep(x,13) is basically x:rep(13)
Leaky Nun
Right! I forgot the string metatable defaultly indexes to the string library.
ATaco
Although good, numbers such as 65+(i%26) don't count as strings unless stored as such. I'll work on a way to make that work for the hell of it.
ATaco
3

Brachylog, 30 24 20 bytes

@Ab:"a"c:@Arz:{:12jc:@Nc.}a:wa
@Ab:"a"c:@Arze:12jcw@Nw\
@A$(:@Arze:12jcw@Nw\

Try it online!

Leaky Nun
la source
3

05AB1E, 12 bytes

ADÀ)øvyJ5Ø×,

Explanation

AD            # push 2 copies of the alphabet
  À           # rotate the 2nd one left by 1
   )ø         # add to list and zip
     v        # for each
      yJ      # join the pair
        5Ø×   # repeat it 13 times
           ,  # print with newline

Try it online

Emigna
la source
I know this is an old question but i just can't help myself. ADÀ)ø13×» works as well with 9 bytes.
Datboi
@Datboi: That does indeed work now, but unfortunately it didn't work at the time this question was posted :(
Emigna
3

Mathematica, 82 75 67 66 bytes

Print@FromCharacterCode@PadLeft[{},26,{i-1,i}~Mod~26+65]~Do~{i,26}

Technically shorter, although it prints in lowercase instead of uppercase:

Mathematica, 64 bytes

Print[""<>FromLetterNumber@Table[{i-1,i}~Mod~26+1,13]]~Do~{i,26}
Michael Lee
la source
1
Nice trick using PadLeft.
Leaky Nun
1

MATLAB, 47 38 bytes

a=(65:90)';char(repmat([a a([2:end 1])],1,13))

char(repmat([65:90;[66:90 65]]',1,13))

The first makes a column array of the alphabet in ASCII, appends a shifted copy as a column to its right, replicates the resulting 26*2 array 13 times columnwise, casts to a character array and prints by default.

The second makes a 2*26 array of alphabet and shifted alphabet, transposes it then continues as above.

user58384
la source
You can save one byte using [... ''] instead of char(...).
pajonk
And you can use simply [65:90;66:90 65] saving two bytes.
pajonk
1

J, 20 19 bytes

1 byte thanks to miles.

u:65+26|(+/2&|)i.26

Online interpreter

This is actually the program I used to generate the text in the challenge.

Leaky Nun
la source
You can remove the @
miles
1

Neoscript, 59 bytes

a=('A:[]:'Z)+'Aeach n=0:[]:25console:log((a[n]+a[n+1])*13);
TuxCrafting
la source
1

PHP, 102 bytes

<?php $a='ABCDEFGHIJKLMNOPQRSTUVWXYZA';$i=-1;while($i++<25){echo str_repeat(substr($a,$i,2),13)."\n";}
gabe3886
la source
You can remove the quotes from the Alphabet string. Replace \n with an actual enter instead of \n. Stole that idea from @insertusernamehere. So check his answer for what I mean. Edit: Also use the short-tag notation <?. You also do not need a space after <?. So <?$a='ABC' also works.
Jeroen
1

Ruby, 41 bytes

26.times{|i|puts [*?A..?Z,?A][i,2]*''*13}
daniero
la source