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

165 Answers 165

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

Powershell, 54 bytes

-join[char[]](0..702|%{if($_%27){--$_%26+65}else{10}})
\$\endgroup\$
1
  • \$\begingroup\$ There is the cool solution from @Joey \$\endgroup\$
    – mazzy
    Jul 5, 2018 at 19:07
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\$
2
  • \$\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, 2018 at 10:45
  • \$\begingroup\$ Heh, I had a solution in 141 that literally shifted an entire list of letters: +++++[<+++++<+++++>>-]>>----[<+>----]<++<<[->>[>]+<[>+>+<<-]>>[<<+>>-]<[<]<]<+[-[>+<-]>>>[.>]++++++++++.[<]>[[>]<+[<]>-]>[>]<----------[<]<<] \$\endgroup\$ Oct 18, 2019 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\$
1
  • \$\begingroup\$ Good work. Maybe I can learn a few tricks from your code. \$\endgroup\$
    – Dorian
    Jul 24, 2018 at 14:48
2
\$\begingroup\$

Brachylog, 11 bytes

25⟦{;Ạ↺₍ẉ}ᵐ

Try it online!

Full program, as it wouldn't be possible for a Brachylog predicate to meet this challenge's restriction on functions (main predicate is defined as the first one, so a call on a later line would simply be ignored), and it's probably easiest to separate it all off into lines with rather than anything else anyhow. Prints the table in lower case with a trailing newline.

25⟦            Range from 0 to 25 inclusive.
   {     }ᵐ    For every number in that range,
    ;Ạ         pair it with the lowercase alphabet,
      ↺₍       rotate the second element of the pair left by the first,
        ẉ      and print it with a newline.
\$\endgroup\$
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\$
2
  • 1
    \$\begingroup\$ 50 bytes \$\endgroup\$
    – ceilingcat
    Mar 7, 2019 at 9:30
  • \$\begingroup\$ @ceilingcat Had a hunch there'd be an optimization in that math, thanks for finding it! \$\endgroup\$ Mar 7, 2019 at 19:56
2
\$\begingroup\$

Perl 5, 32 30 bytes

map{say$_..Z,@b;push@b,$_}A..Z

Try it online!

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

Forth (gforth), 55 bytes

: f 26. do 26. do i j + 26 mod 65 + emit loop cr loop ;

Try it online!

Just for completeness. Tried several tricks (using one loop instead of 2, creating a string before printing) but they didn't save bytes. You can find such attempts in the TIO link above.

How it works

: f ( -- )
  26. do    \ A golfy way to loop from 0 to 25 inclusive
    26. do  \   Form a nested loop
      i j + 26 mod 65 +  \ Compute a char in range A..Z
      emit  \     Print that ASCII char
    loop    \   End inner loop
    cr      \   Print a newline
  loop ;    \ End outer loop
\$\endgroup\$
2
\$\begingroup\$

05AB1E, 4 bytes

Av,À

Try it online!

Av,À  # full program
 v    # for each character in...
A     # "abcdefghijklmnopqrstuvwxyz"...
  ,   # output...
      # (implicit) last popped value
   À  # rotate...
      # (implicit) last popped value...
   À  # one character to the left

P.S. This is my 100th answer!

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

HTML + SCSS, 200 bytes

<p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p><p
*{margin:0}$s:'ABCDEFGHIJKLMNOPQRSTUVWXYZ';@for$i from 1 to 27{p:nth-child(#{$i}):after{content:str-slice($s+$s,$i,$i+25)}}

I was hoping to be able to abuse counters but couldn't make that work in a sensible amount of bytes, also experimented without the p qualifier for the nth-child but this ended up being smaller too. Could be 189 bytes without *{margin:0} but it doesn't look right without it!

Try it online!

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

Perl 5 + -M5.10.0, 28 bytes

$}.=$_ x say$_..Z,$}for A..Z

Try it online!

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

!@#$%^&*()_+, 381 51 48 44 bytes

Z(_^_%!_^_$($%$)$%%)+(%(!@%)+$%  _+%
@_^_)

Try it online!

I'm pretty bad at golfing codes.

if you know something, please tell me in comments.

\$\endgroup\$
2
  • \$\begingroup\$ Beaten \$\endgroup\$
    – null
    Mar 12 at 9:07
  • \$\begingroup\$ My code is hardly golfed though - I keep considering deleting it for that reason, Someone, golf it for me \$\endgroup\$
    – null
    Mar 12 at 9:57
2
\$\begingroup\$

!@#$%^&*()_+, 28 26 bytes

(!*)+(*%(!A*+@%)+$%%
@)

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ Why not posting a comment to golf? \$\endgroup\$
    – Fmbalbuena
    Mar 12 at 12:55
  • \$\begingroup\$ @Fmbalbuena Sorry, I should've asked. \$\endgroup\$
    – null
    Mar 14 at 14:40
1
\$\begingroup\$

Pyke, 14 13 10 bytes

G26V
DtRh+

Try it here!

Ignore function output.

\$\endgroup\$
5
  • \$\begingroup\$ Really need a newline? \$\endgroup\$ Jul 31, 2016 at 16:10
  • 5
    \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ You really don't need to ask the author every single time you see whitespace in an answer whether that whitespace is necessary, especially if you don't know the language. Some whitespace in some languages is significant. And in a case like this, you could at least open the "Try it here" link, remove the linefeed and test your suggestion before posting it. \$\endgroup\$ Jul 31, 2016 at 16:58
  • \$\begingroup\$ @MartinEnder That's because I've got a real life, and I can't just know every programming language ever made... Also, some posts don't have "try it" links. \$\endgroup\$ Jul 31, 2016 at 17:02
  • 7
    \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ Nobody expects you to know every language. The solution is not to learn every language but to stop wasting people's time with random untested golfing suggestions. \$\endgroup\$ Jul 31, 2016 at 17:06
  • \$\begingroup\$ @EʀɪᴋᴛʜᴇGᴏʟғᴇʀ yes the newline does need to be there. \$\endgroup\$
    – Blue
    Jul 31, 2016 at 17:50
1
\$\begingroup\$

Python 3, 55 bytes

i=702
while i:i-=1;print(end=chr(10+(i%27and 80-i%26)))

Similar to my C answer: a single loop, printing the alphabet every 26 characters but with every 27th character replaced by a newline.

\$\endgroup\$
1
\$\begingroup\$

JavaScript, 86 bytes

"ABCDEFGHIJKLMNOPQRSTUVWXYZ".repeat(27).split("").map((n,m)=>m%27==26?"\n":n).join("")

Inspired by Anders Kaseorg's C solution

I decided this answer was different enough from the existing JS solutions to warrant its own answer.

\$\endgroup\$
1
  • \$\begingroup\$ you can use split`` instead of split("") to save some bytes :d \$\endgroup\$
    – NTCG
    Jul 15, 2018 at 21:55
1
\$\begingroup\$

Sesos, 39 bytes

Hexdump:

0000000: 2849b2 6f59be 65f996 e5cbd2 a041d3 eb61c7 6059be  (I.oY.e......A..a.`Y.
0000015: 65e9e7 765a96 a67bd8 315896 6f59fa f93d07         e..vZ..{.1X.oY..=.

Assembler:

add 65,fwd 1,add 26,fwd 1,add 26,fwd 1,add 26,fwd 1,add 10,rwd 1
jmp
  sub 1,rwd 1
  jmp
    sub 1,rwd 1,sub 1,rwd 1,put,add 1,fwd 1
    jmp,rwd 2,jnz
    rwd 1
    jmp,sub 26,fwd 1,add 26,rwd 3,jnz
    fwd 4
  jnz
  add 26,rwd 1
  sub 1,rwd 1,add 1,fwd 1
  jmp,rwd 2,jnz
  rwd 1
  jmp,sub 26,fwd 1,add 26,rwd 3,jnz
  fwd 6,put,rwd 1
jnz

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Python 3, 82 79 69 bytes

A simple nested loop that prints ''.joined lines one at a time. Golfing suggestions are welcome.

Edit: -13 bytes thanks to Leaky Nun.

for i in range(26):print("".join(chr(65+(i+j)%26)for j in range(26)))

Ungolfed:

for row in range(26):
    s = ""
    for column in range(26):
        s += chr(65 + (row+column) % 26)
    print(s)
\$\endgroup\$
0
1
\$\begingroup\$

Emacs Lisp, 117 bytes

(let((s(mapcar'string(number-sequence ?A ?Z))))(dotimes(i 26)(message(apply'concat s))(setcdr(last s)(list(pop s)))))

Uses a list storing the alphabet and always appends the head to the tail. A more general approach would be the following function

(defun tabula-recta (glyphs)
  (dotimes (i (length glyphs))
    (message (apply 'concat glyphs))
    (setcdr (last glyphs) (list (pop glyphs)))))

which could be called in a similar fashion.

(tabula-recta (mapcar'string(number-sequence ?A ?Z)))
\$\endgroup\$
1
\$\begingroup\$

Postscript, 153 bytes of code, 213 bytes for well-structured EPS

You might want your tabula recta in a form you can print out and put a Cardan grille on top of. This is an EPS (Encapsulated Postscript) file, which can be printed as is or embedded in a larger document at whatever scale you like.

%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: 0 0 187 258
/Courier findfont 12 scalefont setfont
0 1 25{dup neg 25 add 10 mul 0 exch moveto
0 1 25{1 index add 26 mod 65 add( )dup 0 4 3 roll put show}for
pop}for
showpage

PostScript is really thorough about its reverse Polish notation, even more so than Forth. This looks cryptic, but hasn't been obfuscated at all, except by minimizing whitespace. The actual computation...

0 1 25 {
    dup
    neg 25 add 10 mul 0 exch moveto
    0 1 25 {
        1 index add 26 mod 65 add
        ( ) dup 0 4 3 roll put
        show
    } for
    pop
} for

... is pretty much the most straightforward way to do this in this language. ("1 string" might be preferred to "( )" but that's longer.)

I used Courier because it's the fixed-width font included in the original core font set, and therefore doesn't have to be embedded in the file.

\$\endgroup\$
1
\$\begingroup\$

Actually, 15 bytes

5Pτr`úi(}akΣ`Mi

Try it online!

Explanation:

5Pτr`úi(}akΣ`Mi
5Pτr             range(26)
    `úi(}akΣ`M   for each element n:
     úi(           lowercase English alphabet, flatten, move n to top
        }          rotate stack left n times
         akΣ       invert stack, push as list, concatenate
              i  flatten
\$\endgroup\$
1
\$\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.
    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\$ 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.
    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\$ 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\$ Aug 1, 2016 at 13:00
1
\$\begingroup\$

Javascript 98 bytes

s="ABCDEFGHIJKLMNOPQRSTUVWXYZ";for (var i = 0; i < 26; i++) {console.log(s);s=s+s[0];s.substr(1);}

try it yourself at: https://jsfiddle.net/dL0vg3cL/1/
sorry i don't know how to do the character count

\$\endgroup\$
4
  • \$\begingroup\$ First, all answers require the byte count in the title. Also, s=s+s.charAt(0) can be written as s+=s[0]. You don't need the var and you have too much whitespace. This should bring down your byte count to a more competitive number. \$\endgroup\$ Aug 2, 2016 at 18:27
  • \$\begingroup\$ @IsmaelMiguel originally there was no white space, someone edited it, and I will use s=s+s[0] thanks for the tip \$\endgroup\$ Aug 2, 2016 at 18:29
  • \$\begingroup\$ You can revert the edit. Then, you simply add 4 spaces at the beginning of your code. This will format it properly. Also, you can use stack snippets to let us try your code, without an external link to jsfiddle. \$\endgroup\$ Aug 2, 2016 at 18:31
  • \$\begingroup\$ @IsmaelMiguel done and i don't know how to use stack snippets on mobile \$\endgroup\$ Aug 2, 2016 at 18:34
1
\$\begingroup\$

Perl 5, 39 36 bytes

print$_%27?chr$_%26+65:$/for-26..675

Similar to my C answer: a single loop, printing the alphabet every 26 characters but with every 27th character replaced by a newline.

Thanks to Dom Hastings for −2 bytes.

\$\endgroup\$
0
1
\$\begingroup\$

C#, 157 Chars

class P{static void Main(){string x="ABCDEFGHIJKLMNOPQRSTUVWXYZ";for(int i=0;i<x.Length;i++)Console.WriteLine(x.Substring(i,x.Length-i)+x.Substring(0,i));}}
\$\endgroup\$
1
  • \$\begingroup\$ You have needless spaces and, apparently, needless braces. \$\endgroup\$
    – asibahi
    Aug 3, 2016 at 8:05
1
\$\begingroup\$

><>, 44 bytes

0:1[\ao]1+:dd+=?;!
$l(?\:1+dd+:@%
ol?!\{"A"+

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Cheddar, 79 bytes

(|>26).map(l->String.letters.slice(l)+String.letters.slice(0,l)).vfuse.slice(1)

Pretty ugly answer. I would of had a much nicer answer if I fixed cycle in time:

(|>26).map(String.letters.cycle).vfuse
\$\endgroup\$
1
\$\begingroup\$

Ruby, 75 42 bytes

a=('A'..'Z').to_a;l=a.length;l.times {l.times {|i|$><<a[i]};a.rotate!;puts}

a=*?A..?Z;26.times {puts a.join;a.rotate!}
\$\endgroup\$
1
  • \$\begingroup\$ Rotate! I was searching so long for this method, but I couldn't remember its name. \$\endgroup\$
    – IMP1
    Feb 17, 2017 at 10:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy