81
\$\begingroup\$

Print a Tabula Recta!

The Tabula Recta (sometimes called a 'Vigenere Table'), was created by Johannes Trithemius, and has been used in several ciphers, including all variants of Bellaso's Vigenere cipher and the Trithemius cipher. It looks like this:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY

I frequently need this, but can't find it anywhere on the internet to copy and paste from. Because the square table is so long, and takes frigging ages to type, your code must be as short as possible.

Rules/Requirements

  • Each submission should be either a full program or function. If it is a function, it must be runnable by only needing to add the function call to the bottom of the program. Anything else (e.g. headers in C), must be included.
  • If it is possible, provide a link to a site where your program can be tested.
  • Your program must not write anything to STDERR.
  • Standard Loopholes are forbidden.
  • Your program can output in any case, but it must be printed (not an array or similar).

Scoring

Programs are scored according to bytes, in UTF-8 by default or a different character set of your choice.

Eventually, the answer with the least bytes will win.

Submissions

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 86986; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 53406; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<div id="answer-list">
  <h2>Leaderboard</h2>
  <table class="answer-list">
    <thead>
      <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>
    </thead>
    <tbody id="answers">

    </tbody>
  </table>
</div>
<div id="language-list">
  <h2>Winners by Language</h2>
  <table class="language-list">
    <thead>
      <tr><td>Language</td><td>User</td><td>Score</td></tr>
    </thead>
    <tbody id="languages">

    </tbody>
  </table>
</div>
<table style="display: none">
  <tbody id="answer-template">
    <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>
<table style="display: none">
  <tbody id="language-template">
    <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr>
  </tbody>
</table>

\$\endgroup\$
  • \$\begingroup\$ Regarding rule 1: do we have to include each header for each function we use? \$\endgroup\$ – owacoder Jul 30 '16 at 15:59
  • \$\begingroup\$ I meant if we use printf, we need to include stdio.h, if isalpha is used, ctype.h is needed, etc. Is this correct? \$\endgroup\$ – owacoder Jul 30 '16 at 16:03
  • 3
    \$\begingroup\$ You should probably put "lowercase is allowed" in the challenge specification itself. Just so people are less likely to miss it if they don't see these comments. \$\endgroup\$ – Sherlock9 Jul 30 '16 at 18:25
  • 2
    \$\begingroup\$ do i have to print it or can i return a string/char array \$\endgroup\$ – downrep_nation Jul 30 '16 at 19:57
  • 1
    \$\begingroup\$ Thanks for the question for making me stay awake all night. (+1) \$\endgroup\$ – Anastasiya-Romanova 秀 Aug 22 '16 at 18:45

139 Answers 139

4
\$\begingroup\$

PHP, 64 62 61 bytes

for($a=join(range(A,Z));$i<26;)echo"
",substr($a.$a,$i++,26);
\$\endgroup\$
  • \$\begingroup\$ I don't know how I haven't seen this solution before! Also, you can use range(A,Z), to save you 4 bytes. (Warnings are ignored, so, don't worry about those. If you are worried, use range(@A,@Z) and save 2 bytes) \$\endgroup\$ – Ismael Miguel Oct 2 '16 at 8:27
  • \$\begingroup\$ You can save one byte with a leading linebreak: echo"\n",substr(...); \$\endgroup\$ – Titus Nov 11 '16 at 11:18
4
\$\begingroup\$

PHP, 241 68 64 bytes

@Jörg Hülsermann kindly offered me this solution. The last one was pretty ridiculous.

for($r=range(A,Z);$i++<26;$r[]=array_shift($r))echo"
",join($r);

Thanks to @Titus for saving me 4 bytes!


@Jörg Hülsermann also provided the following (and longer, with 74 bytes) version:

foreach($a=range(A,Z)as$r)echo strstr($j=join($a),$r),strstr($j,$r,1),"
";

Thank you a lot!

You can try both solutions on http://sandbox.onlinephpfunctions.com/code/1a6a890887d8e817d5e9abbf521885b9306e2186

\$\endgroup\$
  • \$\begingroup\$ You can shorten it to 201 Bytes echo gzdecode(base64_decode('H4sIAAAAAAAAA3XJyRGCAAAEwf9UbVDIIch9CuYfiBFMf7t4lVXdvNvu0w/jNC/rth/n9b2fX9AqgtYraJVBqwpaddBqgtY7aLVBqwtan6DVB60haI1Bawpac9BagtYatLagtQetI2idQesKWt+gdQet5w9+9/hy1gIAAA==')); \$\endgroup\$ – Jörg Hülsermann Oct 1 '16 at 13:00
  • \$\begingroup\$ Other ideas for($r=range(A,Z),$i=26;$i--;$r[]=array_shift($r))echo join($r)."\n"; foreach($a=range(A,Z)as$r)echo strstr($j=join($a),$r).strstr($j,$r,1)."\n"; \$\endgroup\$ – Jörg Hülsermann Oct 1 '16 at 14:14
  • \$\begingroup\$ @JörgHülsermann If you want, post it as your own answer and I will make sure to upvote. \$\endgroup\$ – Ismael Miguel Oct 1 '16 at 20:57
  • \$\begingroup\$ @JörgHülsermann I don't think that that is fair. You had all the work to redude the code significantly. Also, all new answers show at the top. \$\endgroup\$ – Ismael Miguel Oct 1 '16 at 21:54
  • \$\begingroup\$ @JörgHülsermann Are you sure about it? You really should make it your own answer. \$\endgroup\$ – Ismael Miguel Oct 2 '16 at 0:16
4
\$\begingroup\$

Perl6, 36 bytes

say [~] rotate ["A".."Z"],$_ for ^26

rotate takes a list and an integer, and rotates the list by that number of elements. A postfix loop of ^26 (up to 26) assigns the current loop variable (in this case, a number in the range 0..15) which rotates the list 'A'..'Z' by that amount. Finally, I use the concatenate operator ~ as a reduce operator by wrapping it in square brackets, which gets applied to the list.

Thanks to smls for the help.

\$\endgroup\$
  • \$\begingroup\$ You can use [~] to make the second version produce the correct output, and still be shorter than the first: say [~] rotate ["A".."Z"],$_ for ^26 \$\endgroup\$ – smls Jan 21 '17 at 5:38
3
\$\begingroup\$

Jelly, 9 bytes

ØAṙ1$ÐĿj⁷

Try it online!

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

Brainfuck, 203 bytes

Code:

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

Explanation:

At #0
>++[<+++++++++++++>-]< Put 26 in #0
[ 26 times do

  === Get #1 and #2 and #3 to hold count

  > At #1
  [>+>+>+<<<-] Clone #1 into #2 and #3 and #4
  >>>[<<<+>>>-]<<< Move #4 into #1

  === Get #4 to hold 26 minus count which is stored in #0
  < At #0
  [>>>>+>+<<<<<-] Clone #0 into #4 and #5
  >>>>>[<<<<<+>>>>>-]<<<<< Move #5 into #0

  === Now put (count plus 65) into number #5 thereby emptying #2
  === This is the starting number

  >>>>> At #5
  >+++++[<+++++++++++++>-]< Put 65 in #5
  <<<[>>>+<<<-]>>> Add value from #2 to #5

  === Output first '#4' chars starting at #5

  < At #4
  [

    >.+< Output and increase #5

  -]

  === Put 65 in #5

  > At #5
  [-] Empty #5
  >+++++[<+++++++++++++>-]< Put 65 in #5

  === Output first count (#3) chars starting at 65

  << At #3

  [

    >>.+<<

  -]

  === Empty #5 and output newline

  >> At #5
  [-]
  ++++++++++.
  [-]

  === Increase count and prepare end of loop

  <<<<+ At #1 increase
  < At #0

-] end

Try it online!

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

VBA, 89 77 76 bytes

Function v:For i=0To 701:v=v &IIf(26=i Mod 27,vbLf,Chr(65+(i Mod 26))):Next

... the last byte being enter at the end of the line which auto-generates the End Function. Essentially 27 copies of the alphabet with line-feeds overwritten into appropriate spots.

Invoke in the Immediate window with ?v

?v
ABCDEFGHIJKLMNOPQRSTUVWXYZ
BCDEFGHIJKLMNOPQRSTUVWXYZA
CDEFGHIJKLMNOPQRSTUVWXYZAB
DEFGHIJKLMNOPQRSTUVWXYZABC
EFGHIJKLMNOPQRSTUVWXYZABCD
FGHIJKLMNOPQRSTUVWXYZABCDE
GHIJKLMNOPQRSTUVWXYZABCDEF
HIJKLMNOPQRSTUVWXYZABCDEFG
IJKLMNOPQRSTUVWXYZABCDEFGH
JKLMNOPQRSTUVWXYZABCDEFGHI
KLMNOPQRSTUVWXYZABCDEFGHIJ
LMNOPQRSTUVWXYZABCDEFGHIJK
MNOPQRSTUVWXYZABCDEFGHIJKL
NOPQRSTUVWXYZABCDEFGHIJKLM
OPQRSTUVWXYZABCDEFGHIJKLMN
PQRSTUVWXYZABCDEFGHIJKLMNO
QRSTUVWXYZABCDEFGHIJKLMNOP
RSTUVWXYZABCDEFGHIJKLMNOPQ
STUVWXYZABCDEFGHIJKLMNOPQR
TUVWXYZABCDEFGHIJKLMNOPQRS
UVWXYZABCDEFGHIJKLMNOPQRST
VWXYZABCDEFGHIJKLMNOPQRSTU
WXYZABCDEFGHIJKLMNOPQRSTUV
XYZABCDEFGHIJKLMNOPQRSTUVW
YZABCDEFGHIJKLMNOPQRSTUVWX
ZABCDEFGHIJKLMNOPQRSTUVWXY
\$\endgroup\$
  • \$\begingroup\$ @Joffran, this is a very clever abuse of the nature of Modulus... I applaud you... bravo! \$\endgroup\$ – WallyWest Aug 1 '16 at 1:28
  • \$\begingroup\$ Somehow, I tried to run your program but nothing returned. What happened? FWIW, I managed to obtain VBA code with a length exactly 76 bytes. Here is my code: for j=1to 26:a="ABCDEFGHIJKLMNOPQRSTUVWXYZ":?mid(a,j,27-j)&mid(a,1,j-1):next \$\endgroup\$ – Anastasiya-Romanova 秀 Aug 22 '16 at 18:16
  • \$\begingroup\$ You're outgolfed :) \$\endgroup\$ – Anastasiya-Romanova 秀 Aug 22 '16 at 18:43
  • \$\begingroup\$ @Anastasiya-Romanova秀 Each submission should be either a full program or function. \$\endgroup\$ – Joffan Aug 23 '16 at 6:43
  • \$\begingroup\$ @Joffan It is a full program, try it. Anyway, why I couldn't get output from your code? \$\endgroup\$ – Anastasiya-Romanova 秀 Aug 23 '16 at 6:47
3
\$\begingroup\$

Dyalog APL, 10 11 bytes

(↑⍳∘⍴⌽¨⊂)⎕A

TryAPL online!

Requires ⎕IO←0 which is standard on many systems.

The generalized 7-char function is just ↑⍳∘⍴⌽¨⊂:

make the following list of strings into a character table:
    the indices
     of
     the length of the argument, i.e [1, 2, 3, ..., 26]
⌽¨ each rotate
     the entire argument

With the argument of ⎕A (uppercase alphabet) we get the desired result, but any argument can be fed to get the corresponding cipher:

      f←↑⍳∘⍴⌽¨⊂
      f'o+×'
o+×
+×o
×o+

In fact, even strings and numbers are allowed:

      f'Alpha' 'Bravo' 'Charlie' 'Delta'
┌───────┬───────┬───────┬───────┐
│Alpha  │Bravo  │Charlie│Delta  │
├───────┼───────┼───────┼───────┤
│Bravo  │Charlie│Delta  │Alpha  │
├───────┼───────┼───────┼───────┤
│Charlie│Delta  │Alpha  │Bravo  │
├───────┼───────┼───────┼───────┤
│Delta  │Alpha  │Bravo  │Charlie│
└───────┴───────┴───────┴───────┘
      f⍳8
0 1 2 3 4 5 6 7
1 2 3 4 5 6 7 0
2 3 4 5 6 7 0 1
3 4 5 6 7 0 1 2
4 5 6 7 0 1 2 3
5 6 7 0 1 2 3 4
6 7 0 1 2 3 4 5
7 0 1 2 3 4 5 6
\$\endgroup\$
3
\$\begingroup\$

Julia, 49 bytes

println.(join.((n->circshift('A':'Z',n)).(0:25)))

Requires julia v0.5 or better for the .() broadcasting function calls.

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

8086 machine code, 44 bytes

00000000  bf 2c 01 57 b0 1b 98 89  c1 51 b1 1a 89 cb b0 41  |.,.W.....Q.....A|
00000010  aa fe c0 e2 fb 59 e2 f1  89 d9 5f 57 8d 39 b0 0a  |.....Y...._W.9..|
00000020  aa e2 f9 c6 05 24 b4 09  5a cd 21 c3              |.....$..Z.!.|
0000002c

How it works:

            |   org 0x100
            |   use16
bf 2c 01    |       mov di, string
57          |       push di
b0 1b       |       mov al, 27
98          |       cbw
89 c1       |       mov cx, ax
51          |   a:  push cx
b1 1a       |       mov cl, 26
89 cb       |       mov bx, cx
b0 41       |       mov al, 'A'
aa          |   @@: stosb
fe c0       |       inc al
e2 fb       |       loop @b
59          |       pop cx
e2 f1       |       loop a
89 d9       |       mov cx, bx
5f          |       pop di
57          |       push di
8d 39       |   @@: lea di, [di+bx]
b0 0a       |       mov al, 0x0a
aa          |       stosb
e2 f9       |       loop @b
c6 05 24    |       mov byte [di], '$'
b4 09       |       mov ah, 0x09
5a          |       pop dx
cd 21       |       int 0x21
c3          |       ret    
            |   string rb 0
\$\endgroup\$
  • \$\begingroup\$ so amazing, teach me senpai :p \$\endgroup\$ – NTCG Jul 15 '18 at 21:54
3
\$\begingroup\$

Common Lisp, SBCL, 97 94 90 bytes

(dotimes(i 26)(format t"~a~a
"(#1=subseq #2="ABCDEFGHIJKLMNOPQRSTUVWXYZ"i 26)(#1##2#0 i)))

Try it online!

Explanation

#2="ABCDEFGHIJKLMNOPQRSTUVWXYZ";save alphabet to #2# and return it
(dotimes(i 26);loop from i=0 to i=25
(format t"~a~a
"(#1=subseq #2="ABCDEFGHIJKLMNOPQRSTUVWXYZ"i 26)(#1##2#0 i)));display concatenation of subseqences of alpabet
 (#1##2#0 i) works like (subseq "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 0 i)

Ideas for improvement are welcomed. Could rotatef be better here?

-1 byte thanks to Renzo explicitly

-3 bytes by applying knowledge from Renzo's comment, using #2# for alphabet instead of using set and using <enter> instead of ~%.

\$\endgroup\$
  • \$\begingroup\$ You can save 1 byte (!) with the sharpsign-number: (dotimes(i 26)(format t"~a~a~%"(#1=subseq(set's"ABCDEFGHIJKLMNOPQRSTUVWXYZ")i 26)(#1#s 0 i))) \$\endgroup\$ – Renzo Jul 21 '17 at 14:40
  • \$\begingroup\$ @Renzo Thank you! I didn't know you can write #1#s with no space between #1# and s. That can save me some bytes in other challenges. Using that knowledge and also changing set into #N= macro and using <enter> instead of ~% additional 3 bytes can be saved:) \$\endgroup\$ – user65167 Jul 21 '17 at 21:58
3
\$\begingroup\$

QBasic, 57 bytes

FOR i=0TO 701
?CHR$(10-(i MOD 27<26)*(55+i MOD 26));
NEXT

Basically the same as Anders Kaseorg's Python 2 answer, though independently derived: Run a single loop from 0 to 701; the letter to print is the loop index mod 26; but every 27th iteration, instead of printing the letter, print a newline. Saves 3 bytes over the naive nested-loop approach.

Note that QBasic's display is 25 lines tall by default, so you won't see the whole table. One way to resolve this is to add SCREEN 11 at the beginning, since screen mode 11 is 30 lines tall.

\$\endgroup\$
2
\$\begingroup\$

JavaScript, 110 bytes

My answer might be sub-optimal, but I think my method is cool enough to warrant using it.

a="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
b=a.split("")  
b.map((n,m)=>b.map((o,p,q,r=m)=>a[(q+p)%26].join("")).join("\n")

Tested in the Firefox browser console.

\$\endgroup\$
  • \$\begingroup\$ This is neat. I tried to auto-generate my seed A-Z, but you've inspired me to just include it as a string. Thanks for the input! \$\endgroup\$ – Polyducks Jul 30 '16 at 21:36
  • \$\begingroup\$ b and a have the same characters at the same indices, so you don't need to store the string into a. In fact, you don't even have to store the array into b either - it's the 3rd parameter to the map callback. Also, use [..."A...Z"] rather than "A...Z".split(""). \$\endgroup\$ – Neil Jul 30 '16 at 22:54
  • \$\begingroup\$ Oh, and I forgot to mention you can use join`` instead of join("") and when you do that you can actually put a literal newline in the string rather than \n. \$\endgroup\$ – Neil Jul 30 '16 at 22:55
2
\$\begingroup\$

Ruby, 42 36 bytes

-3 bytes from @MartinEnder, -3 bytes from @xsot

Try it online!

a=*?A..?Z
a.map{puts a*'';a.rotate!}
\$\endgroup\$
  • \$\begingroup\$ It's a bit shorter if you rotate after printing: repl.it/ChtJ/1 \$\endgroup\$ – Martin Ender Jul 31 '16 at 11:10
  • \$\begingroup\$ In addition to Martin's improvement, you can also change 26.times to a.map. \$\endgroup\$ – xsot Jul 31 '16 at 12:39
2
\$\begingroup\$

><>, 54 52 bytes

Prints two newlines after the grid, instead of one.

'6'd*1-::?!v1-60.
.2co-$'Z'%*r!d2<
%,2'6':;!?l<~oa^?

Try it online!

Explanation

'6'd*1-                     push 701 onto stack
       ::?!v1-60.           push numbers 700..0 onto the stack
           r                reverse, stack top now contains 701. goto (1)
    -$'Z'%* !d2<            (2) calculate 'Z' - (stack top % 26)
   o                        output letter
.2c                         jump to (1)
       ;!?l<                (1) if stack is empty, we're done
%,2'6':                     duplicate stack top, mod 27
            ~oa^?           if non-zero, goto (2), else print a newline and pop stack top.
\$\endgroup\$
2
\$\begingroup\$

F#, 74 bytes

for i=0 to 25 do(for j=0 to 25 do printf"%c"<|char((j+i)%26+65));printfn""

Pretty straightforward

\$\endgroup\$
2
\$\begingroup\$

Clojure, 106 105 89 88 80 bytes

(print(apply str(map #(char(if(< 25(mod % 27))10(+ 65(mod % 26))))(range 702))))

Old version 87 bytes:

(for[i(range 26)](prn(String.(byte-array(flatten(reverse(split-at i(range 65 91))))))))

Mod approach pretty much minimized to the limit, still looking for a way to shorten the line version

\$\endgroup\$
2
\$\begingroup\$

Awk, 73 bytes

awk 'BEGIN{for(a="ABCDEFGHIJKLMNOPQRSTUVWXYZ";i<26;)print substr(a a,++i,26)}'

Edit: Dennis saved me a few bytes. And I learned a new Awk trick.

\$\endgroup\$
  • 3
    \$\begingroup\$ Welcome to Programming Puzzles & Code Golf! This is a standalone awk program; you don't have to count the invocation. Also, this saves a few more bytes. \$\endgroup\$ – Dennis Aug 3 '16 at 3:11
2
\$\begingroup\$

Jellyfish, 19 17 bytes

Thanks to Zgarb for saving 4 bytes.

This answer is non-competing, since Zgarb fixed a few bugs to make this valid.

P& ,`r"[Z
 \26 'A

Try it online

Explanation

`r"[Z
 'A

This creates the following array by threading range('A', ...) over the pair "[Z":

["ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXY"]

Then , flattens this into a single string.

Finally this bit gets all substrings of length 26:

&
\26

And P prints the result in matrix format, one string per line.

\$\endgroup\$
2
\$\begingroup\$

PHP, 47 42 bytes

for($s="
A";$p<702;$s++)echo$s[++$p%27>0];

using string increment. Run with -nr.

hints: $s=_A;$s++; <=> $s=_B; and $s=_Z;$s++; <=> $s=_A;.
I use newline instead of underscore to further exploit the indexing.

43 bytes with PHP >= 7.1 (for the negative indexing):

for($s=A;$s<ZZ;$s++)echo++$p%27?$s[-1]:"
";

hints: $s=A;$s++; <=> $s=B;, $s=Z;$s++; <=> $s=AA; and $s=AZ;$s++; <=> $s=BA;

older 47 bytes version:

for(;$p++<702;)echo chr($p%27?($p-1)%26+65:10);

Why use "\n" if I already use chr()? :D

\$\endgroup\$
2
\$\begingroup\$

oK, 16 bytes

`c$26':51#65+!26

Explanation:

          65+!26 / letters A to Z
       51#       / double the list, except for Z
   26':          / sliding window of size 26
`c$              / convert to characters
\$\endgroup\$
2
\$\begingroup\$

Sinclair ZX81/Timex TS1000/1500, 127 bytes 92 bytes 88 bytes (listing)

 1 LET A$="ABCDEFGHIJKLMNOPQSTUVWXYZ"
 2 SCROLL
 3 PRINT A$
 4 LET A$=A$(2 TO)+A$(1)
 5 GOTO 2

The string is declared in one line, rather than looping through the character set and building up the string from an empty one.

It then manipulates the built string like a scrolly text, making this an easy challenge for 8 bit programmers.

You can try it online by typing in the listing using JtyOne online emulator. Good luck with that.

\$\endgroup\$
2
\$\begingroup\$

R, 44 bytes

Immediately outgolfed by Robert Hacken.

write(matrix(LETTERS,27,26)[-27,],"",26,,"")

Try it online!

Explanation of the golf:

The other two R answers each use were using a cat-based approach, using some pretty clever indexing tricks.

Using write, though, which is really a wrapper for cat, we automatically get to break the data into lines, and since there isn't a ... argument in write, we can use positional matching to shorten things like sep, although we do still have to specify file.

So the only missing part is generating the data in a golfy way. matrix automatically recycles its argument (going down rows), so I originally had matrix(LETTERS,27,27), which generates

ABCDEFGHIJKLMNOPQRSTUVWXYZA
BCDEFGHIJKLMNOPQRSTUVWXYZAB
CDEFGHIJKLMNOPQRSTUVWXYZABC
DEFGHIJKLMNOPQRSTUVWXYZABCD
EFGHIJKLMNOPQRSTUVWXYZABCDE
FGHIJKLMNOPQRSTUVWXYZABCDEF
GHIJKLMNOPQRSTUVWXYZABCDEFG
HIJKLMNOPQRSTUVWXYZABCDEFGH
IJKLMNOPQRSTUVWXYZABCDEFGHI
JKLMNOPQRSTUVWXYZABCDEFGHIJ
KLMNOPQRSTUVWXYZABCDEFGHIJK
LMNOPQRSTUVWXYZABCDEFGHIJKL
MNOPQRSTUVWXYZABCDEFGHIJKLM
NOPQRSTUVWXYZABCDEFGHIJKLMN
OPQRSTUVWXYZABCDEFGHIJKLMNO
PQRSTUVWXYZABCDEFGHIJKLMNOP
QRSTUVWXYZABCDEFGHIJKLMNOPQ
RSTUVWXYZABCDEFGHIJKLMNOPQR
STUVWXYZABCDEFGHIJKLMNOPQRS
TUVWXYZABCDEFGHIJKLMNOPQRST
UVWXYZABCDEFGHIJKLMNOPQRSTU
VWXYZABCDEFGHIJKLMNOPQRSTUV
WXYZABCDEFGHIJKLMNOPQRSTUVW
XYZABCDEFGHIJKLMNOPQRSTUVWX
YZABCDEFGHIJKLMNOPQRSTUVWXY
ZABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZA

This is almost the right answer, just I'd need to remove the last row and column, e.g., matrix(LETTERS,27,27)[-27,-27]. This is 47 bytes, which is as good as one of the R answers. But the recycling doesn't change for a 27x26 matrix, and that neatly drops the last column, allowing me to remove the second -27 index.

\$\endgroup\$
2
\$\begingroup\$

Fortran (GFortran), 91 bytes

DO I=0,25
DO J=0,25
WRITE(*,'(A)',ADVANCE='NO')CHAR(MOD(J+I,26)+65)
ENDDO
PRINT*,
ENDDO
END

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Python 3, 64 bytes

e='ABCDEFGHIJKLMNOPQRSTUVWXYZ';exec('print(e);e=e[1:]+e[0];'*26)

Try it online!

\$\endgroup\$
2
\$\begingroup\$

sed 4.2.2 + bash, 48 + 2 (-rn) = 56 54 51 50 bytes

s/$/printf %c {A..Z}/e
:
P
s/^([^Z])(.+)/\2\1/
t

Try it online!

Explanation

s/$/printf %c {A..Z}/e  # Set the pattern space to "printf %c {A..Z}" and
                        # set the result of that to the pattern space
:                       # Unnamed label
P                       #  Print the pattern space
s/^([^Z])(.+)/\2\1/     #  Move the first letter (it should not be a `Z`) to the end of the first line
t                       # Loop until the pattern space does not change
                        # The -n flag suppresses implicit printing of the pattern space at the end of the program

Pure sed 4.2.2, 57 + 2 (-rn) = 59 bytes

s/$/ABCDEFGHIJKLMNOPQRSTUVWXYZ/
:
P
s/^([^Z])(.+)/\2\1/
t

Try it online!

\$\endgroup\$
2
\$\begingroup\$

T-SQL, 98 bytes

DECLARE @ CHAR(26)='ABCDEFGHIJKLMNOPQRSTUVWXYZ'a:PRINT @
SET @=RIGHT(@,25)+@ IF'A'<LEFT(@,1)GOTO a

A couple of things make this work like it does:

  • Fixing the CHAR type at 26 means I don't have to manually trim the string after I double it.
  • Found through testing that RIGHT() is shorter than SUBSTRING() or STUFF().
  • Rearranging the order of my IF allowed me to save a character, plus one more by using < instead of <>, since that's a valid string comparison. (Although, strictly speaking, character ordering will depend on the SQL collation used; practically, though, I know of no collation that will order these particular characters differently.)
\$\endgroup\$
2
\$\begingroup\$

brainfuck, 127 122 120 113 bytes

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

Try it online!

Or visualize it!

Should run on all interpreters. No value wrapping or pointer wrapping, no negative values or pointers, cell size doesn't matter, no undefined input behaviour.

Explanation

Initialize tape:
10(lf) 26(rowCount) 0(colCountBuffer) 26(colCount) 0(letterCountBuffer) 26(letterCount) 65("A") 0(temp) 0(exit if)
+++++ +++++ +++[->+>++>>++>>++>+++++<<<<<<<]>---


>[                  for each rowCount
  -                   decrement rowCount
  >>[                 for each colCount
    <+                  increment colCountBuffer
    >-                  decrement colcount
    >+                  increment letterCountBuffer
    >>.+                print and increment letter
    <-                  decrement letterCount
    [                   if letterCount still greater 0
      >>                  go to temp
    ]
    >[                  else (if letterCount = 0);(pointer position letter = true; exit if = false)
      <<[->+>-<<]         restore letterCount and letter "A"
      >>>>                go to exit if
    ]
    <<<<<               return to colCount
  ]
  >+                  increment letterCountBuffer
  >-                  decrement letterCount
  >+                  increment letter
  <<<<[->+<]          restore colCount
  <<.                 print lf
  >                   return to rowcount
]          
\$\endgroup\$
  • \$\begingroup\$ Should run on all interpreters. No value wrapping or pointer wrapping, no negative values or pointers, cell size doesn't matter, no undefined input behaviour. \$\endgroup\$ – Dorian Jul 16 '18 at 10:45
  • \$\begingroup\$ Heh, I had a solution in 141 that literally shifted an entire list of letters: +++++[<+++++<+++++>>-]>>----[<+>----]<++<<[->>[>]+<[>+>+<<-]>>[<<+>>-]<[<]<]<+[-[>+<-]>>>[.>]++++++++++.[<]>[[>]<+[<]>-]>[>]<----------[<]<<] \$\endgroup\$ – JosiahRyanW Oct 18 at 10:07
2
\$\begingroup\$

Brain-Flak, 160 bytes

(((((()()()()){}))[]{}{})<>()){({}[()]<<>(({})<>){(({})[()])}{}>)}{}{<>(({})<([{<({}[()]<<>({}<>)>)>()()}{}()()])>)<>{}}<>{}{({}(((((()()){}){}){}){}){}<>)<>}<>

Try it online!

Prints two trailing newlines, though one is from the interpreter.

Like Dorian's answer, this pushes 27 alphabets before processing anything. However, this solution stores it as the values 1 to 26 and adds 64 at the end.

Explanation:

(
((((()()()()){}))[]{}{})  # Push 26 as the letter counter
<>())                     # Push 27 as the alphabet counter
{({}[()]<   # Repeat 27 times
      <>(({})<>)     # Copy the 26 from the other stack
      {(({})[()])}{} # Create a descending range from 26 to 1
>)}{}

{  # Loop until we're out of letters
  <>(({})  # Save a copy of the 26
  <([
  {
    <({}[()]<   # Loop 26 times
	<>({}<>)
    >)>
    ()()  # Add 2 every loop
  }{}()()])  # Use the loop to push -(26*2+2) = -54
  >)   # Push the copy of 26
  <>{} # Pop a letter
}
<>{}  # Pop the 26
{({}  # Reverse the stack
  (((((()()){}){}){}){}){}  # Adding 64 to every element
<>)<>}<>
\$\endgroup\$
  • \$\begingroup\$ Good work. Maybe I can learn a few tricks from your code. \$\endgroup\$ – Dorian Jul 24 '18 at 14:48
2
\$\begingroup\$

C, 73 63 60 bytes


60 bytes: (note, someone optimized to 50 in the comments)

i=~0;f(){for(;i++<701;)putchar(~i%27?65+(i%27+i/27)%26:13);}

63 btyes:

i=~0;f(){for(;i++<701;)putchar(i%27==26?13:65+(i%27+i/27)%26);}

73 bytes:

a;i=-2;f(){for(;i++<24;){for(a=0;a++<26;putchar(65+(i+a)%26));puts("");}}

\$\endgroup\$
  • 1
    \$\begingroup\$ 50 bytes \$\endgroup\$ – ceilingcat Mar 7 at 9:30
  • \$\begingroup\$ @ceilingcat Had a hunch there'd be an optimization in that math, thanks for finding it! \$\endgroup\$ – Albert Renshaw Mar 7 at 19:56
1
\$\begingroup\$

CJam, 15 bytes

'[,65>{_n(+}25*

Try it online!

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