95
\$\begingroup\$

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\$
14
  • \$\begingroup\$ Regarding rule 1: do we have to include each header for each function we use? \$\endgroup\$
    – owacoder
    Commented Jul 30, 2016 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
    Commented Jul 30, 2016 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
    Commented Jul 30, 2016 at 18:25
  • 2
    \$\begingroup\$ do i have to print it or can i return a string/char array \$\endgroup\$ Commented Jul 30, 2016 at 19:57
  • 1
    \$\begingroup\$ Thanks for the question for making me stay awake all night. (+1) \$\endgroup\$ Commented Aug 22, 2016 at 18:45

173 Answers 173

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\$
2
  • \$\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\$ Commented Aug 1, 2016 at 15:58
  • \$\begingroup\$ Nicely done. Looks much better than my try! thanks \$\endgroup\$
    – Dada
    Commented Aug 1, 2016 at 17:19
4
\$\begingroup\$

PHP, 64 62 61 bytes

for($a=join(range(A,Z));$i<26;)echo"
",substr($a.$a,$i++,26);
\$\endgroup\$
2
  • \$\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\$ Commented Oct 2, 2016 at 8:27
  • \$\begingroup\$ You can save one byte with a leading linebreak: echo"\n",substr(...); \$\endgroup\$
    – Titus
    Commented Nov 11, 2016 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\$
9
  • \$\begingroup\$ You can shorten it to 201 Bytes echo gzdecode(base64_decode('H4sIAAAAAAAAA3XJyRGCAAAEwf9UbVDIIch9CuYfiBFMf7t4lVXdvNvu0w/jNC/rth/n9b2fX9AqgtYraJVBqwpaddBqgtY7aLVBqwtan6DVB60haI1Bawpac9BagtYatLagtQetI2idQesKWt+gdQet5w9+9/hy1gIAAA==')); \$\endgroup\$ Commented Oct 1, 2016 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\$ Commented Oct 1, 2016 at 14:14
  • \$\begingroup\$ @JörgHülsermann If you want, post it as your own answer and I will make sure to upvote. \$\endgroup\$ Commented Oct 1, 2016 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\$ Commented Oct 1, 2016 at 21:54
  • \$\begingroup\$ @JörgHülsermann Are you sure about it? You really should make it your own answer. \$\endgroup\$ Commented Oct 2, 2016 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\$
1
  • \$\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
    Commented Jan 21, 2017 at 5:38
4
\$\begingroup\$

Convey, 200 bytes

Dude, this take me a lot of time, its my first time using this incredible esoteric language so probably is not very golfed :P

  ['b',<+1 '|'v
    } >>">>>>>=
  ]</<"$"^v27 v
 '{'  v^">#>>v>!26
   ="<,<@.=  v v
   .v   ^ "1 v v
   >@v  ^ ^?,$2v
   >$,  "v^]+$1v
'a'?;,"+^v^<<^ v
    ^ v1 >>>>@<"
[1>>^}@<<<<<<#<<
      ]      ]

Try it online!

Visual representation of the program:

Image of the program mid execution

I would like to put a gif of the functionality but the process is too long and the gif is too big. Use the try it online and play it four yourself, is very cool :)

\$\endgroup\$
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\$
5
  • \$\begingroup\$ @Joffran, this is a very clever abuse of the nature of Modulus... I applaud you... bravo! \$\endgroup\$ Commented Aug 1, 2016 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\$ Commented Aug 22, 2016 at 18:16
  • \$\begingroup\$ You're outgolfed :) \$\endgroup\$ Commented Aug 22, 2016 at 18:43
  • \$\begingroup\$ @Anastasiya-Romanova秀 Each submission should be either a full program or function. \$\endgroup\$
    – Joffan
    Commented Aug 23, 2016 at 6:43
  • \$\begingroup\$ @Joffan It is a full program, try it. Anyway, why I couldn't get output from your code? \$\endgroup\$ Commented Aug 23, 2016 at 6:47
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\$

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\$
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\$
1
  • \$\begingroup\$ so amazing, teach me senpai :p \$\endgroup\$
    – NTCG
    Commented Jul 15, 2018 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\$
2
  • \$\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
    Commented Jul 21, 2017 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
    Commented Jul 21, 2017 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\$
3
\$\begingroup\$

Knight, 53 bytes

;=s*"ZABCDEFGHIJKLMNOPQRSTUVWXY"=i 26WiO Gs*25=i-iT26

Native Knight doesn't (currently) have a way to convert to and from ascii (there's discussions about adding one, though). As such, we have to just write the entire alphabet out. Expanded out:

# just make a massive string that we'll index into.
; = str * "ZABCDEFGHIJKLMNOPQRSTUVWXY" (= i 26)
: WHILE i # while nonzero
    : OUTPUT GET (
        s # get from s
        (* 25 (= i (- i 1)) # starting at position 25 * --i
        26) # and get 26 characters
\$\endgroup\$
1
  • \$\begingroup\$ 50 bytes: ;=i 0W>26iO G*"ZABCDEFGHIJKLMNOPQRSTUVWXY"2=i+iT26 \$\endgroup\$
    – EasyasPi
    Commented May 26, 2021 at 18:07
3
\$\begingroup\$

BQN, 16 14 13 bytes (SBCS)

-2 bytes thanks to ovs -1 byte thanks to Razetime

My first ever BQN program and also my first ever program in an array language.

Outputs as a table of strings.

(⍋⌽⌜⋈)'A'+↕26

Try it online!

Explanation

(⍋⌽⌜⋈)'A'+↕26
       'A'+↕26 - Make a range from A to Z
( ⌽⌜⋈)        - Enlist and rotate (as table)...
 ⍋            - 0..25 times.
\$\endgroup\$
2
  • 2
    \$\begingroup\$ You can store ↕26 in a variable to save two bytes: x⌽⌜⟨'A'+x←↕26⟩ \$\endgroup\$
    – ovs
    Commented Dec 8, 2021 at 11:43
  • 1
    \$\begingroup\$ -1: (⍋⌽⌜⋈)'A'+↕26 \$\endgroup\$
    – Razetime
    Commented Dec 10, 2021 at 10:08
2
\$\begingroup\$

CJam, 15 bytes

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

Try it online!

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

Pyth, 12 10 7 bytes

jP.:*2rG1 26
j.<LrG1 26
j.<LG26

Try it online!

It is a mistake to suddenly allow lowercase output.

\$\endgroup\$
0
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\$
3
  • \$\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
    Commented Jul 30, 2016 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
    Commented Jul 30, 2016 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
    Commented Jul 30, 2016 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\$
2
  • \$\begingroup\$ It's a bit shorter if you rotate after printing: repl.it/ChtJ/1 \$\endgroup\$ Commented Jul 31, 2016 at 11:10
  • \$\begingroup\$ In addition to Martin's improvement, you can also change 26.times to a.map. \$\endgroup\$
    – xsot
    Commented Jul 31, 2016 at 12:39
2
\$\begingroup\$

Java 1.8, 106 101 bytes

Simply prints every character as a byte, followed by a line feed (which forces a flush on the line-buffered System.out stream), by using mod operations.

interface C{static void main(String[]a){for(int i=-1;++i<702;)System.out.write(i%27>25?10:i%26+65);}}

Run it.

Shaved off a few bytes thanks to @KevinCruijssen

Initially my attempts had a pre-defined alphabet string, since I had a hard time generating the sequence with less characters. The shortest version I managed to find basically runs a 26-character window over a string that contains the alphabet twice:

151 bytes

class G{public static void main(String[]a){String s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";s+=s;int i=0;while(i<26){System.out.println(s.substring(i,++i+25));}}}

Run it

\$\endgroup\$
6
  • \$\begingroup\$ @KevinCruijssen: Actually, no. print() would print the integer value of i, whereas write() prints the byte value (and thus a character). :) You can of course use print() to print the character value, but that would require an extra 6 bytes for the cast ((char)). \$\endgroup\$
    – MH.
    Commented Aug 1, 2016 at 12:31
  • \$\begingroup\$ Yeah, realized that soon after I made my comment and therefore deleted it. :) Never really used .write tbh, and I'm kinda confused why class M{public static void main(String[]a){int t=88;System.out.write(t);}} doesn't print anything unless I'm adding a System.out.flush(); while your answer works just fine without.. \$\endgroup\$ Commented Aug 1, 2016 at 12:40
  • 1
    \$\begingroup\$ Ah, that's why your comment disappeared as soon as I posted mine. :) Your question is answered by write()'s doc: "If the byte is a newline and automatic flushing is enabled then the flush method will be invoked." So the reason the answer works is because it writes a newline character at the end of every line and auto flush is enabled for System.out(search for "line buffered"). \$\endgroup\$
    – MH.
    Commented Aug 1, 2016 at 12:50
  • \$\begingroup\$ Thanks for the explanation! There are already like 3-4 Java answers for this challenge, but yours is the shortest and to the point. Btw, you can golf it by 2 bytes by removing the { and } from the for-loop, since you only have one line in it. Also, you don't have to include the class & main method in your byte-count unless the question states otherwise. Since it states: "Each submission should be either a full program or function.", just void f(){for(int i=-1;++i<702;)System.out.write(i%27>25?10:i%26+65);} would suffice as answer. \$\endgroup\$ Commented Aug 1, 2016 at 12:58
  • \$\begingroup\$ Also, I just notice you are new here on PPCG. So welcome! :) You might also find Tips for Golfing in Java an interesting post to take a look at. \$\endgroup\$ Commented Aug 1, 2016 at 13:00
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, 89 86 85 59 chars

after @manatwork optimisation :

awk 'BEGIN{for(;n++<27;)for(c=64;++c<91;)printf"%c",++i%27?c:RS}'

--

before @manatwork optimisation: 85 chars (91 including awk invocation)

awk 'BEGIN{for(;n++<27;)for(c=64;++c<91;){if(++i%27){printf "%c",c}else{print;continue;}}}'

A little less efficient than @mattk answer, though... well done!

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Too many braces around single instruction blocks. BEGIN{for(;n++<27;)for(c=65;c<91;c++)printf"%c",++i%27?c:RS}. \$\endgroup\$
    – manatwork
    Commented Aug 3, 2016 at 13:20
  • \$\begingroup\$ @manatwork: ohh, very nice : i was wondering how to use "?:" for this, your usage is so much better than my (big) "if... else" \$\endgroup\$ Commented Aug 3, 2016 at 13:23
  • 1
    \$\begingroup\$ As Dennis wrote, “This is a standalone awk program; you don't have to count the invocation.” \$\endgroup\$
    – manatwork
    Commented Aug 3, 2016 at 13:37
  • \$\begingroup\$ @manatwork: thanks, it saves 6 more bytes ^^ (I'm (kind of) new to this...) \$\endgroup\$ Commented Aug 3, 2016 at 13:39
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\$
1
  • 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
    Commented Aug 3, 2016 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\$

Ruby, 43 bytes

26.times{|i|puts(([*?A..?Z]*2)[i,26].join)}

Explanation

[*?A..?Z]
This creates a list from 'A' to 'Z', using ruby's literal character syntax ?A and the splat operator on a range.

It then doubles this list, and cycles through it 26 times, printing out 26 characters with an increasing offset.

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

Japt, 10 9 bytes

8 bytes of code, +1 for the -R flag.

26Æ;BéXn

Try it online!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.