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

133 Answers 133

30
\$\begingroup\$

05AB1E, 6 5 bytes

Thanks to Downgoat for saving 1 byte. Code:

ADv=À

Explanation:

A      # Push the lowercase alphabet.
 D     # Duplicate it.
  v    # For each in the alphabet...
   =   #   Print without popping and with a newline.
    À  #   Rotate 1 to the left.

Uses the CP-1252 encoding. Try it online!.

\$\endgroup\$
  • \$\begingroup\$ What is the purpose of duplicating it? \$\endgroup\$ – Esolanging Fruit Nov 19 '16 at 19:32
  • 1
    \$\begingroup\$ @Challenger5 The v command consumes a value, iterating over it. In this case, it consumes the alphabet, so it iterates 26 times. That's also the exact amount of times we need to iterate of the function. The = leaves the stack intact and the À only rotates the top of the stack element 1 to the left. Does this answer your question? :) \$\endgroup\$ – Adnan Nov 19 '16 at 20:01
101
\$\begingroup\$

Vim, 25 23 bytes

:h<_↵jjYZZP25@='Ypx$p'↵

Where is the Return key.

:h<_↵                       Open the help section v_b_<_example.
     jjY                    Copy the "abcdefghijklmnopqrstuvwxyz" line.
        ZZP                 Close this buffer and paste in ours.
           25@='     '↵     Run these commands 25 times:
                Yp          Duplicate line and move to column 1 of new line.
                  x         Cut the first character.
                   $p       Move to the end and paste.

GIF of solution

EDIT: lowercase is okay, so I can save two keys.

\$\endgroup\$
  • 23
    \$\begingroup\$ That :h<_<cr>jjY is genius \$\endgroup\$ – Downgoat Jul 30 '16 at 18:18
  • 3
    \$\begingroup\$ Wow, that's amazing! OP said lowercase was OK so you can remove V~ \$\endgroup\$ – DJMcMayhem Jul 30 '16 at 18:22
  • 4
    \$\begingroup\$ @RobStarling see: meta.codegolf.stackexchange.com/q/8995/40695 \$\endgroup\$ – Downgoat Jul 30 '16 at 22:57
  • 4
    \$\begingroup\$ I dare someone to try this in emacs. \$\endgroup\$ – addison Jul 31 '16 at 3:49
  • 2
    \$\begingroup\$ @addison Emacs answer \$\endgroup\$ – TuxCrafting Aug 3 '16 at 13:09
24
\$\begingroup\$

Python 2, 59 57 53 bytes

a=range(65,91)*27
a[::-27]=[10]*26
print bytearray(a)

Thanks to @xsot for -4 bytes!

\$\endgroup\$
  • 4
    \$\begingroup\$ I like this one. By the way, you can shorten the last line to print bytearray(a). \$\endgroup\$ – xsot Jul 31 '16 at 4:44
18
\$\begingroup\$

///, 220 bytes

/|/\/\///n/WXY|m/JKL|l/PQRS|k/CDEF|j/ZaNfV|i/MbAeI|h/TUcO|g/GHdB|f/OlTU|e/BkGH|d/ImMbA|c/VnZaN|b/NfVnZ|a/AeImM/ab
ed
kg
DEFgC
EFgCD
FgCDE
gk
HdBkG
de
mi
KLiJ
LiJK
im
ba
fc
lh
QRShP
RShPQ
ShPQR
hl
UcOlT
cf
nj
XYjW
YjWX
jn

Try it online!

This was surprisingly non-trivial and I have no clue whether it's optimal.

The only way to golf a problem like this in /// is by extracting common substrings. (Turns out I was wrong.) However, due to the nature of the output it's not at all clear which substrings should best be extracted since you can't actually extract the entire alphabet due to the linebreaks. So you'll need to extract some substrings of the wrapped alphabet, but then there are trade-offs in terms of how long you make the substrings and which ones you choose.

So here's what I did. This is a CJam script which finds all substrings up to length 25 in the given string and for each of them computes how many bytes its extracting would save. Basically if there are N copies of a length-M substring, you'd save (N-1)*(M-1) - 5 substrings, these substrings don't contain slashes. Also, technically, when you've already extract 8 substrings or so, the constant offset at the end reduces to -4, but the script doesn't consider that.

Anyway, here's what I did with the script:

  • Run the script against the current code (which is initially just the output).
  • Out of the substrings that yield the largest improvement, pick the shortest one. If there are several, pick the lexicographically smallest (from what I can tell, for the given input this reduces overlaps between substrings).
  • Replace all occurrences of the chosen substring in the code with an unused lower case letter.
  • Prepend /x/ABC/ to the code where x is the chosen letter and ABC is the substring.
  • Repeat until there are no substrings left that would save anything.

At the end, we save a few more bytes by replacing the resulting // with | and prepending /|/\/\// (this is why extracting substrings only costs 4 instead of 5 bytes after the 8th substring or so).

Like I said, I have no clue whether this is optimal and I find the rather irregular-looking result quite interesting. It might be possible to get to a shorter solution by chosing non-optimal (but more) substrings somewhere down the line. I wonder what the complexity class of this problem is...

\$\endgroup\$
  • \$\begingroup\$ That... is... brilliant... \$\endgroup\$ – George Gibson Jul 31 '16 at 11:12
  • 1
    \$\begingroup\$ @GeorgeGibson Thanks... I had to start over halfway through when I noticed a certain YX in the output. ;) \$\endgroup\$ – Martin Ender Jul 31 '16 at 11:13
  • \$\begingroup\$ My answer is gone, it was a dupe of this (bigger and later). +1 for that [incredible golfing]! \$\endgroup\$ – Erik the Outgolfer Aug 1 '16 at 8:51
  • \$\begingroup\$ Regarding complexity class, shouldn't the problem be undecidable since /// is Turing complete? The problem is "given a string, find the shortest /// program that outputs it". Except for small strings, there would exist /// programs that loop indefinitely (but cannot be proven to loop indefinitely) that cannot be shown to not produce the desired output without running them forever. Formal proof I'm myself not sure yet but intuitively isn't it possible? \$\endgroup\$ – ghosts_in_the_code Jun 1 at 14:07
16
\$\begingroup\$

C, 47 bytes

i;f(){for(i=702;i--;)putchar(i%27?90-i%26:10);}

Try it on Ideone

A single loop, printing the alphabet every 26 characters but with every 27th character replaced by a newline.

\$\endgroup\$
  • 1
    \$\begingroup\$ Damn! I just wrote the exact same function! :-) You can save the first semicolon by using f(i) then just call f() without any arguments. \$\endgroup\$ – Level River St Jul 31 '16 at 2:23
  • \$\begingroup\$ @LevelRiverSt That would be relying on undefined behavior. \$\endgroup\$ – Anders Kaseorg Jul 31 '16 at 3:07
  • 2
    \$\begingroup\$ It's ultimately up to you, but PPCG considers languages to be defined by their implementations, so as long as you mention in which compiler it works, relying on UB is not considered a problem. \$\endgroup\$ – Dennis Jul 31 '16 at 5:53
  • \$\begingroup\$ you can shave 1 byte by initializing i when first mentioned: i=702;f(){for(;i--;)//... \$\endgroup\$ – tucuxi Aug 2 '16 at 12:49
  • 3
    \$\begingroup\$ @tucuxi No, because function answers have to be reusable. \$\endgroup\$ – Anders Kaseorg Aug 2 '16 at 20:14
15
\$\begingroup\$

J, 15 bytes

u:65+26|+/~i.26

Online interpreter.

u:65+26|+/~i.26
           i.26  creates vector [0 1 2 ... 25]
        +/~      builds an addition table with itself
     26|         modulo 26 to every element
  65+            add 65 to every element
u:               convert every element from codepoint to character
\$\endgroup\$
  • \$\begingroup\$ Nice! Very clever arithmetic. The simplest approach that uses |. (Shift) is 8 bytes longer! (i.26)(|."0 _)u:65+i.26 \$\endgroup\$ – Dan Oak Jul 30 '16 at 18:55
  • 1
    \$\begingroup\$ @dahnoak You can shorten it to 16 bytes u:65+1&|.^:]i.26 since the power adverbs tracks previous results if given a list. \$\endgroup\$ – miles Jul 30 '16 at 22:53
  • 1
    \$\begingroup\$ @miles Nice, my approach using |. is 17 bytes: u:65+|."0 1/~i.26 (still using /~) \$\endgroup\$ – Leaky Nun Jul 30 '16 at 23:04
  • 1
    \$\begingroup\$ @LeakyNun Another 17 byte approach is u:65+(|./~,.)i.26. I got rid of the rank by using a hook and ,. to columnize the range but it ended up the same length. \$\endgroup\$ – miles Jul 30 '16 at 23:19
  • \$\begingroup\$ don't you know if I can find the source code of tryj.tk somewhere? I couldn't find any info neither about it neither about the author (f211) \$\endgroup\$ – Dan Oak Aug 5 '16 at 11:27
15
\$\begingroup\$

///, 128 bytes

/:/fABCDEFGHIJKLMNOPQRSTUVWXYZ
fbfbAfxf
xbA_xf_x
xfbbbAfbb//x/bff//f/\///b/\\:B:C:D:E:F:G:H:I:J:K:L:M:N:O:P:Q:R:S:T:U:V:W:X:Y:Z:

Try it online!

Inspired by Jakube's amazing answer to the L-phabet challenge, I thought I'd try my hand as well at actual programming in /// as opposed to just using it for compression. This was pretty tricky and I needed four attempts, but in the end it came out much shorter than my compression-based solution.

Explanation

A quick primer on ///: basically the interpreter just reads the code character by character and does the following:

  • If it's neither a \ nor a /, print it.
  • If it's a \, print the next character.
  • If it's a /, parse a /x/y/ instruction (with the same escaping rules) and repeatedly substitute all x in the remaining code with y.

Taking some more inspiration from Jakube, for simplicity I'll just explain a 4x4 version of this:

/:/fABCD
fbfbAfxf
xbA_xf_x
xfbbbAfbb//x/bff//f/\///b/\\:B:C:D:

We start by replacing those : with the stuff between the second and third /. This will end up being the code the rotates the subsequent rows. We get this:

/x/bff//f/\///b/\\fABCD
fbfbAfxf
xbA_xf_x
xfbbbAfbbBfABCD
fbfbAfxf
xbA_xf_x
xfbbbAfbbCfABCD
fbfbAfxf
xbA_xf_x
xfbbbAfbbDfABCD
fbfbAfxf
xbA_xf_x
xfbbbAfbb

The f, b and x are just shorthands for common strings, which we'll expand now. The f is for slashes, the b is for backslashes and the x is for \// which happens to come up quite a lot. The reason I'm using aliases for the single-character substrings / and \ is that they'd have to be escaped in the first substitution instruction, so I'm actually saving quite a lot of bytes by not needing all those backslashes. Here's what we get after x, f and b have been filled in:

ABCD
/\/\A/\///
\//\A_\///_\//
\///\\\A/\\B/ABCD
/\/\A/\///
\//\A_\///_\//
\///\\\A/\\C/ABCD
/\/\A/\///
\//\A_\///_\//
\///\\\A/\\D/ABCD
/\/\A/\///
\//\A_\///_\//
\///\\\A/\\

Very readable.

So the first line is just printed verbatim. Then we get to the funky part that rotates all further rows. It actually consists of four different instructions. One thing to notice is that I've escaped all occurrences of A within these instructions. The reason for this is that it allows me to distinguish As within the instructions from As in the remaining rows, which need to be processed differently.

/\/\A/\//

This matches /A and replaces it with /, removing the A. Note that this substring only appears at the front of each ABCD, so this drops the first character of all subsequent lines:

/
\//\A_\//

This matches a linefeed followed by a slash and replaces it with A_/. So this inserts an A at the end of each line, completing the rotation and also turns the linefeed into an underscore.

/_\//
\//

This matches _/ and replaces it with a linefeed followed by a slash. The reason I need to make this detour via the underscore is the fact that /// applies each instruction repeatedly until the string no longer matches. That means you can never use an instruction of the form /x/axb/ where x, a and b are arbitrary strings, because after the substitution x will always still match. In particular, this means we can't just insert something in front of a linefeed. We need to replace the linefeed in the process and the undo this replacement.

/\\\A/\\B/

This matches \A and replaces it with \B, so that the instructions after the remaining rows process the next character. After all four instructions have been processed the remaining string looks like this:

BCDA
/\/\B/\///
\//\B_\///_\//
\///\\\B/\\C/BCDA
/\/\B/\///
\//\B_\///_\//
\///\\\B/\\D/BCDA
/\/\B/\///
\//\B_\///_\//
\///\\\B/\\

So now the first rotated row gets printed, and then the next set of instructions rotates the remaining rows by another cell and so on. After the last rotation, we have a few more instructions that we can ignore and then we end with the incomplete instruction:

/\\\B/\\

Incomplete instructions at the end are simply ignored and the program terminates.

\$\endgroup\$
  • \$\begingroup\$ Nice one. Yesterday I experimented a little bit with a different idea. I wanted to substitute each character in each line. Something like A->B, B->C, ... But it didn't quite work. Removing the first char and appending it at the end is definitly a much better approach. \$\endgroup\$ – Jakube Aug 2 '16 at 8:56
  • \$\begingroup\$ @Jakube I tried that as well but wasn't getting anywhere. It's too hard to avoid messing up the subsequent instructions as well. \$\endgroup\$ – Martin Ender Aug 2 '16 at 9:42
  • 1
    \$\begingroup\$ 124 bytes: goo.gl/efSLKQ This is just your solution, but I've managed add a few additional substitutions, so that you only need to write out the alphabet once. Used the same strategy on similar problem as well. \$\endgroup\$ – Jakube Sep 10 '17 at 19:12
  • 1
    \$\begingroup\$ 122: goo.gl/zRsBbR \$\endgroup\$ – Jakube Sep 10 '17 at 19:17
11
\$\begingroup\$

Jelly, 7 bytes

ØAṙJṢj⁷

Try it online!

How it works

ØAṙJṢj⁷  Main link. No arguments.

ØA       Set argument and return value to "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
   J     Yield the indices of the argument, i.e., [1, ..., 26].
  ṙ      Rotate the alphabet 1, ..., 26 units to the left.
         This generates all rotations, but not in the correct order.
    Ṣ    Sort the rotated alphabets.
     j⁷  Join, separating by linefeeds.
\$\endgroup\$
11
\$\begingroup\$

Emacs, 47 bytes

abcdefghijklmnopqrstuvwxyz^M
^P
<F3>
^K ^K ^Y ^Y
^P
^<space> ^F ^W ^E ^Y ^A
<F4>
^U 2 4 F4

Where ^P means "Control P", etc. That's 47 bytes, since the F3 and F4 keys require two ASCII bytes.

After entering the starting input, it defines a keyboard macro to duplicate the line and move the first character to the end. It then runs the macro a further 24 times.

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to PPCG, nice answer! It's very rare to see a Emacs answer, I don't even know if a Emacs answer already have been posted. \$\endgroup\$ – TuxCrafting Aug 3 '16 at 12:59
10
\$\begingroup\$

JavaScript (ES6), 56 bytes

_=>"ABCDEFGHIJKLMNOPQRSTUVWXYZ".replace(/./g,"$&$'$`\n")

Yes, that's right, half my code is the alphabet string literal. Best I could do without the literal is 81 bytes:

_=>[...Array(26)].map((_,i,a)=>a.map(_=>(i++%26+10).toString(36)).join``).join`
`

If you want a program rather than a function, then remove the _=> and wrap in console.log() for a cost of 10 bytes.

\$\endgroup\$
  • \$\begingroup\$ Woah, well done. A very elegant solution. How does it work? \$\endgroup\$ – Polyducks Aug 8 '16 at 10:16
  • 2
    \$\begingroup\$ @Polyducks Lots and lots of regexp magic. Naturally /./g matches each letter of the supplied alphabet string. In the replacement string, $& represents the match itself, $' the part of the string after the match and $` the part of the string before the match. $`$&$' would therefore represent the original string, but of course it's trivial to move the part after the match to the beginning, thus providing the rotation effect. \$\endgroup\$ – Neil Aug 8 '16 at 10:41
  • \$\begingroup\$ Super smart! Well done @Neil! \$\endgroup\$ – Polyducks Aug 9 '16 at 14:04
9
\$\begingroup\$

Mathematica 68 61 bytes

Column[""<>RotateLeft["A"~CharacterRange~"Z",#]&/@0~Range~25]

Thanks to...

@MartinEnder (7 bytes)

\$\endgroup\$
  • \$\begingroup\$ Also, Array might be shorter that mapping over a Range. \$\endgroup\$ – Martin Ender Jul 30 '16 at 16:21
  • \$\begingroup\$ I just checked and Array does indeed save a byte, but you can then save another by avoiding Column: Array[{"A"~CharacterRange~"Z"~RotateLeft~#,"\n"}&,26,0]<>"" (you'll just need to replace the \n with an actual linefeed). \$\endgroup\$ – Martin Ender Jul 30 '16 at 16:31
  • 7
    \$\begingroup\$ Wait no built-in? Impossible \$\endgroup\$ – MC ΔT Jul 31 '16 at 13:35
  • 1
    \$\begingroup\$ Print@@@NestList[RotateLeft,"A"~CharacterRange~"Z",25] \$\endgroup\$ – alephalpha Aug 1 '16 at 17:21
  • \$\begingroup\$ Grid@Array[FromCharacterCode[Mod[+##-2,26]+65]&,{26,26}] \$\endgroup\$ – mathe Jul 28 '17 at 7:59
9
\$\begingroup\$

Python 2, 75 65 61 58 bytes

a='%c'*26%tuple(range(65,91))
for x in a:print a;a=a[1:]+x

Gets the alphabet with map(chr,range(65,91)), then manually applies the string shift operation.

Thanks to @LeakyNun and @TheBikingViking for -4 bytes!

Thanks to @xnor for -3 bytes!

\$\endgroup\$
  • 2
    \$\begingroup\$ Apparently a="ABCDEFGHIJKLMNOPQRSTUVWXYZ" is shorter. \$\endgroup\$ – Leaky Nun Jul 30 '16 at 16:49
  • 1
    \$\begingroup\$ You can do a[1:] instead of a[1:26]. \$\endgroup\$ – TheBikingViking Jul 30 '16 at 17:40
  • 2
    \$\begingroup\$ Your loop can be done as for x in s:print s;s=s[1:]+x. \$\endgroup\$ – xnor Jul 30 '16 at 21:09
  • 3
    \$\begingroup\$ You can do one byte shorter than hardcoding the alphabet: s='%c'*26%tuple(range(65,91)). \$\endgroup\$ – xnor Jul 30 '16 at 21:24
9
\$\begingroup\$

C, 88 64 bytes

Call f() without arguments.

f(i,j){for(i=j=0;i<26;putchar(j==26?j=0,i++,10:65+(i+j++)%26));}

Try it on ideone.

\$\endgroup\$
9
\$\begingroup\$

Piet, 247 bytes/190 codels

Tabula Recta in Piet

Try it Online!

So, this took far longer than I had anticipated, and I have a few ideas on some other more efficient (more stack-friendly) approaches, but I finally got the dang thing working (and fixed an interpreter bug and added IDE features along the way), so here it is. Hardly the most byte-efficient language, but a hell of a lot of fun. Here's a larger view, and a trace showing the path taken. History up on my GitHub.

Tabula Recta in Piet, large version

Tabula Recta run trace

As a stack-based language, it's far too convoluted to explain briefly, but here's a basic overview of what the various sections/loops do. All variable and function names are just for explanation, as there are no variables or functions in Piet.

  • Initialization (upper-left): starts line_counter at 27, loads '@' as cur_letter, sets letter_count to 27
  • Main loop (starting at dark purple, center top)
    • Decrements letter_counter
    • Branches to reset_line if zero (light cyan 2-block)
    • Rolls cur_letter to the top of the stack
    • Branches to check_done if cur_letter > 'X' (teal/red block, right side)
    • Increments cur_letter and outputs it (lower-right corner)
    • Branches to reset_letter if cur_letter > 'Y' (light green block, left)
    • Rolls `letter_counter_ back to top of stack, back to top of loop
  • reset_line branch (big pink square):
    • Outputs newline character
    • Resets letter_count to 27
    • Continues back to top of main loop
  • check_done branch (right half inside)
    • Rolls line_counter to top
    • Branches to end if zero
    • Decrements line_counter and rolls back to bottom of stack
    • Resumes where it left off, printing letter
  • reset_line branch (left side, green block):
    • Resets cur_letter to '@'
    • Resumes where it left off, rolling/returning to top of loop
\$\endgroup\$
8
\$\begingroup\$

MATL, 8 bytes

With thanks to @Dennis, who suggested that MATL should incorporate modular indexing, and to @Suever, who had the idea of automatic pairwise operations.

1Y2t&+Q)

Try it online!

1Y2    % Predefined literal: string 'AB...Z'
t      % Push another copy of it
&+     % 2D array with all pairwise additions of ASCII code points from that string.
       % Gives the 26×26 array [130 131... 155; 131 132... 146; ...; 155 156... 180] 
Q      % Add 1 to each element. First entry is now 131, etc
)      % Index into string 'AB...Z'. Since it has length 26 and MATL uses modular
       % indexing, 131 is the first entry (character 'A'), etc. Implicitly display
\$\endgroup\$
8
\$\begingroup\$

Javascript, 113 96 91 76 bytes

A super-short version for running in the console:

l="ZABCDEFGHIJKLMNOPQRSTUVWXY";for(C=26;C--;console.log(l=l.slice(1)+l[0]));

Javascript/HTML, 140 123 118 105 bytes

A prettier version, with an HTML output that makes it easier for OP to copy and paste:

<script>l="ABCDEFGHIJKLMNOPQRSTUVWXYZ";for(C=26;C--;document.write(l+"<br>"),l=l.slice(1)+l[0]);</script>

(EDIT: I should've just used the string A-Z instead of generating it)

(EDIT 2: Thanks to @Neil and @DanTheMan for their input (see comments))

\$\endgroup\$
  • \$\begingroup\$ Isn't the first C=26 irrelevant? \$\endgroup\$ – DanTheMan Jul 30 '16 at 21:57
  • \$\begingroup\$ Oh snap. Looks like I forgot to delete it when I moved it to the for. Fixed! Thanks @DanTheMan :) \$\endgroup\$ – Polyducks Jul 30 '16 at 22:00
  • 1
    \$\begingroup\$ l.slice(0,1) is just l[0], while the ,27 is unnecessary, at which point you can move the slice and end up with l.slice(1)+l[0]. Also I think you can move the console.log to the loop body thus avoiding the trailing ;. \$\endgroup\$ – Neil Jul 30 '16 at 22:46
  • \$\begingroup\$ Testing this now, thanks @Neil! EDIT: Sweet holy moly. Thanks to you both, I'll add you to credit in the comment. \$\endgroup\$ – Polyducks Jul 30 '16 at 22:48
  • 1
    \$\begingroup\$ Ooh, nice, that's an even better way of simplifying the console.log. \$\endgroup\$ – Neil Jul 30 '16 at 23:06
8
\$\begingroup\$

PowerShell, 44 bytes

-1..24|%{-join[char[]](65..90)[($_-25)..$_]}
\$\endgroup\$
8
\$\begingroup\$

R, 47 42 41 bytes

write(rep(LETTERS,27)[-27*1:26],1,26,,'') 

Try it online!

Generates 27 alphabetes, removes 27-th letters and prints in 26 columns.

Improvement inspired by @Giuseppe's solution.

\$\endgroup\$
  • 1
    \$\begingroup\$ 46 bytes \$\endgroup\$ – Giuseppe Jan 31 '18 at 18:49
  • \$\begingroup\$ Wow, I thought I had tried every indexing trick to use rep but this was particularly inspired! Very nice. I'd upvote again if I could. \$\endgroup\$ – Giuseppe Feb 1 '18 at 19:28
  • \$\begingroup\$ you can use 1 instead of "" for stdout. \$\endgroup\$ – Giuseppe Mar 22 '18 at 19:02
6
\$\begingroup\$

Sesos, 27 25 bytes

0000000: 685902 ae7b33 764992 c45d9b 397360 8fef1f 7bca72  hY..{3vI..].9s`...{.r
0000015: 3adc33 07

Try it online! Check Debug to see the generated SBIN code.

Sesos assembly

The binary file above has been generated by assembling the following SASM code.

add 26
jmp
    jmp
        rwd 1, add 1, rwd 1, add 1, fwd 2, sub 1
    jnz
    rwd 2, add 64
    jmp
        fwd 2, add 1, rwd 2, sub 1
    jnz
    fwd 1, sub 1
jnz
fwd 1
jmp
    jmp
        put, fwd 1
    jnz
    rwd 27
    jmp
        put, fwd 1
    jnz
    add 10, put, get, fwd 1
    jmp
        rwd 1, add 1, fwd 1, sub 1
    jnz
    fwd 1
; jnz (implicit)

How it works

We start by initializing the tape to ABCDEFGHIJKLMNOPQRSTUVWXYZ. This is as follows.

Write 26 to a cell, leaving the tape in the following state.

                                                     v
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26 0

As long as the cell under the data head is non-zero, we do the following.

Copy the number to the two cells to the left and add 64 to the leftmost copy.

                                                   v
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 90 26 0 0

Move the leftmost copy to the original location, then subtract 1 from the rightmost copy.

                                                     v
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 90 0

The process stops after 26 iterations, since the rightmost copy is 0 by then. We move a cell to the right, so the final state of the tape after the initialization is the following.

     v
0 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

Now we're ready to generate the output, by repeating the following process until the cell under the data head is zero.

First, we print the character under the data head and move to the right, repeating this step until a cell with value 0 is found. After printing ABCDEFGHIJKLMNOPQRSTUVWXYZ, the tape looks as follows.

                                                                                v
0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

Now we move the data head 27 units to the left (back to the leading 0) and repeat the print-move combination until a cell with value 0 is found. This prints nothing and leaves the tape as follows.

v
0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

Now, we write 10 to the current cell, print the corresponding character (linefeed) and zero the cell with a call to get on empty input, leaving the tape unchanged.

Afterwards, we move the content of the cell to the right to the current cell, then move the data head to units to the right.

      v
65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

The next iteration is slightly different. The first printing step prints BCDEFGHIJKLMNOPQRSTUVWXYZ, leaving the tape as follows.

                                                                                v
65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

Now we move the data head 27 units to the left.

 v
65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

The subsequent printing loop prints A and leaves the tape as follows.

   v
65 0 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

Once again, we print a linefeed, move the content of the cell to the right to the current cell, then move the data head to units to the right.

         v
65 66 0 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0

After 24 more iterations, the final step of moving the data head to the right leaves the tape in the following state.

                                                                                v
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 0 0

The cell under the data head is now 0 and the program terminates.


TIO uses a newer version of Sesos, which is backwards-compatible for SASM, but generates shorter SBIN code.

\$\endgroup\$
6
\$\begingroup\$

Haskell, 56 53 52 Bytes

mapM(\x->putStrLn$init$[x..'Z']++['A'..x])['A'..'Z']

same length: (using a suggestion by @AndersKaseorg)

a=['A'..'Z']
mapM putStrLn[take 26$[x..'Z']++a|x<-a]

to do modular stuff you have to import Data.Char to get the chr function, 74 59 58 Bytes was the best I could get with that: (thanks to @nimi for suggesting the toEnum function)

a=[0..25]
mapM(\x->putStrLn[toEnum$65+(x+y)`mod`26|y<-a])a

This could probably be much shorter, but I don't know any Haskell golfing tricks.

used mapM instead of mapM_ (see @Lynn's comment)

\$\endgroup\$
  • 1
    \$\begingroup\$ For −3 bytes, change ['A'..x] to ['A'..'Z'], which is now used twice, and lift that to a definition. \$\endgroup\$ – Anders Kaseorg Jul 30 '16 at 20:38
  • \$\begingroup\$ @AndersKaseorg: Thanks! However, I got another idea which saved the same number of bytes while keeping it a oneliner. I added your suggestion to the alternative solution, though. \$\endgroup\$ – KarlKastor Jul 30 '16 at 22:14
  • \$\begingroup\$ If you only need chr from Data.Char, you can use toEnum instead and omit the import. \$\endgroup\$ – nimi Jul 30 '16 at 22:51
  • 1
    \$\begingroup\$ I feel like changing mapM_ to mapM should be fine. Maybe this is worth a meta post… \$\endgroup\$ – Lynn Jul 31 '16 at 8:12
6
\$\begingroup\$

R, 53 bytes

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

Here it is on an online interpreter.

\$\endgroup\$
5
\$\begingroup\$

Retina, 36 31 bytes

5 bytes thanks to Martin Ender.


Z
{2`
$`
}T01`L`_L
\`.
$&$'$`¶

Leading linefeed is significant.

Try it online!

Credits.

\$\endgroup\$
5
\$\begingroup\$

Brain-Flak, 222 bytes

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

Try it online!

I'm new to Brain-Flak, so maybe this can be golfed a lot, but at least it's a first try. It stores 27 full alphabets on the left stack, then moves the alphabets to the right and replaces every 27th letter by a newline.

My sourcecode is a bit confusing, but i will add it nevertheless.

(((()()()()){})
    park 8 in third
    <(((({}){}){}){})> push 64
)
((((([[]]{}){}()){}))<>()) push 26 twice on left and 27 on right
left stack: 64 letter, 26 letter count, 26 constant
right stack: 27 alphabet count
{ while alphabet count
    <>
    ({}<>)<> push 26 back to right
    { while counter
        (
            {} park counter in third
                <(({}()))> add next letter to stack
            [()] decrement counter
        )
    }
    {} pop 0 counter
    <>([({})]<>{}) set Z back to A-1
    <>(({}<>)) move 26 twice from right to left
    <> go to right stack
    ({}[()]) decrement counter
}
{} pop 0
<>(({}<>)) push 26 twice on right stack
<>{}{}{} pop counter, @ and Z from left stack
<> go to right stack
{ while alphabet count
    (
        {} save alphabet count on third stack
        <(
            ({}())[()] save constant on third stack and push lettercount 26 + 1 for lf
            <
                {   while lettercount
                    (
                        {} save lettercount on third stack
                        <
                            <>({}<>) pull letter from left to right
                        > 
                        [()] decrement lettercount
                    )
                }
                {} pop 0
                {} pop last letter
                ((()()()()()){}) push lf
            >
        )>
        [()] decrement alphabet count
    )
}
{}{}{} pop alphabet count, constant and lf
\$\endgroup\$
5
\$\begingroup\$

V, 36, 10 bytes

¬AZ25ñÙx$p

Try it online!

This uses the "Latin1" encoding.

Explanation:

¬AZ         " Insert the alphabet
   25ñ      " 25 times...
      Ù     "   Duplicate this line
       x    "   Cut the first character
        $p  "   Move to the end of the line and past the character we just cut
\$\endgroup\$
  • \$\begingroup\$ Go and add it then ;) \$\endgroup\$ – Conor O'Brien Aug 4 '16 at 7:36
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ You should know by now that the only way anything gets done in this language is at a snails pace. I'll probably have that up and running sometime next January. :P \$\endgroup\$ – DJMcMayhem Aug 4 '16 at 9:25
  • \$\begingroup\$ Oh, in the next 6-8 weeks? \$\endgroup\$ – Conor O'Brien Aug 4 '16 at 18:00
4
\$\begingroup\$

C#, 98 bytes

I have tried to see if I can generate the letters shorter than just initializing them as a string, but it's not really possible. The letters are 26 bytes and this snippet alone

for(char a='A';a<'[';a++)

is 25 bytes. I think initializing them and then appending them with a+=a is a good solution, but with C# you are limited by the bytecount of functions like Substring() and Console.WriteLine().

My attempt at 98 bytes:

var a="ABCDEFGHIJKLMNOPQRSTUVWXYZ";a+=a;for(int i=0;i<26;i++)Console.WriteLine(a.Substring(i,26));
\$\endgroup\$
4
\$\begingroup\$

Octave, 27 bytes

We're adding a row and a column vector, and Octave nicely expands the sigleton dimensions, no need for bsxfun (as you would need in Matlab).

[mod((v=0:25)+v',26)+65,'']
\$\endgroup\$
4
\$\begingroup\$

q, 20 bytes

(til 26)rotate\:.Q.A
\$\endgroup\$
  • \$\begingroup\$ 14 bytes -1_'26 27#.Q.A \$\endgroup\$ – streetster Jul 5 '18 at 19:08
4
\$\begingroup\$

Java, 190 176 172 163 bytes

class C{public static void main(String[] a){int s=0;while(s<26){p(s,26);p(0,s++);p(-1,0);}}static void p(int s,int e){for(;s<e;s++)System.out.write(s<0?10:65+s);}}
\$\endgroup\$
  • \$\begingroup\$ You can easily shave off some more bytes: System.out.printf("%c", ...) -> System.out.write(...), '\n' -> 10, 'A' -> 65. Note sure the newline/line feed char suggestion is allowed, but ideone output requirement. :) \$\endgroup\$ – MH. Jul 31 '16 at 13:34
  • \$\begingroup\$ @MH. great tips! saved 9 bytes :) \$\endgroup\$ – Master_ex Jul 31 '16 at 14:19
  • \$\begingroup\$ I know it's been more than a year since you've answered this, but you can still golf a few things: The space at String[]a can be removed; and int s=0;while(s<26){p(s,26);p(0,s++);p(-1,0);} can be for(int s=0;s<26;p(0,s++),p(0,s++))p(s,26);. \$\endgroup\$ – Kevin Cruijssen Sep 18 '17 at 9:58
4
\$\begingroup\$

Bash, 66 bytes

A=`printf %c {A..Z}`
for i in {0..25};do echo ${A:$i}${A::$i};done

I create a full alphabet in A, then print 26 rotated versions of it by taking the characters beginning at n and appending those preceding position n.

\$\endgroup\$
4
\$\begingroup\$

Perl, 42 bytes

Full credit to @Dom Hastings for this.

@l=A..Z;say@l[$_..25],@l[0..$_-1]for 0..25  

Or (same byte count) :

$_=join"",A..Z;eval'say;/./;$_=$\'.$&;'x26

Needs -M5.010 or -E to run, for instance :

perl -E '@l=A..Z;say@l[$_..25],@l[0..$_-1]for 0..25'



My old answer (55 bytes) :

@t=A..Z;for$i(0..25){print$t[($_+$i)%26]for 0..25;say}

Need -M5.010 to run. So run with :

perl -M5.010 -e '@t=A..Z;for$i(0..25){print$t[($_+$i)%26]for 0..25;say}'  

It's probably possible to do shorter though, but i didn't find out how... yet

\$\endgroup\$
  • \$\begingroup\$ Managed to come up with a couple of 42 byte solutions: @l=A..Z;say@l[$_..25],@l[0..$_-1]for 0..25 and $_=join"",A..Z;eval'say;/./;$_=$\'.$&;'x26 both require -E/-M5.010. \$\endgroup\$ – Dom Hastings Aug 1 '16 at 15:58
  • \$\begingroup\$ Nicely done. Looks much better than my try! thanks \$\endgroup\$ – Dada Aug 1 '16 at 17:19

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.