The English language and most programming languages are written and read from left-to-right, top-to-bottom, but that needn't be the case.
In fact for the block of text
ABC
DEF
I can think of eight related ways it might be read:
- Left-to-right, top-to-bottom (LTR-TTB):
ABCDEF
- Top-to-bottom, left-to-right (TTB-LTR):
ADBECF
- Left-to-right, bottom-to-top (LTR-BTT):
DEFABC
- Bottom-to-top, left-to-right (BTT-LTR):
DAEBFC
- Right-to-left, top-to-bottom (RTL-TTB):
CBAFED
- Top-to-bottom, right-to-left (TTB-RTL):
CFBEAD
- Right-to-left, bottom-to-top (RTL-BTT):
FEDCBA
- Bottom-to-top, right-to-left (BTT-RTL):
FCEBDA
Challenge
Write a rectangular block of text that can be read in each of the eight ways above as eight single line programs in your language of choice. Each of these programs should output a different integer from one to eight.
It doesn't matter which reading direction outputs which number, they do not have to match the numbers above. For example, if your text block were still
ABC
DEF
then the program ABCDEF
might output 5
and FEDCBA
might output 2
, and the other six programs would output 1
, 3
, 4
, 6
, 7
, and 8
in some order.
The text block may contain any characters except line terminators.
Output should go to stdout or a similar alternative if your language doesn't have a proper stdout. There is no input. You may assume the programs are run in a REPL environment.
Pietu1998 charitably wrote a JSFiddle that gives the 8 different single line programs when given a block of text. I've made it into a stack snippet:
<script>function f(n){n=n.split("\n");var e=n.map(function(n){return n.length}).sort()[n.length-1];n=n.map(function(n){return(n+Array(e+1).join(" ")).substring(0,e)});var t=n[0].split("").map(function(e,t){return n.map(function(n){return n[t]}).join("")});n=[n.join(""),n.reverse().join(""),t.join(""),t.reverse().join("")],n=n.concat(n.map(function(n){return n.split("").reverse().join("")})),document.getElementById("a").innerHTML=n.map(function(n,e){return document.getElementById("b").checked?n+" "+"LLTTRRBB"[e]+"T"+"RRBBLLTT"[e]+"-"+"TBLRBTRL"[e]+"T"+"BTRLTBLR"[e]:n}).join("\n")}</script><textarea onkeyup="f(this.value)" id="c" placeholder="Code"></textarea><br/><input type="checkbox" id="b" onchange="f(document.getElementById('c').value)" checked/> <label for="b">Show directions</label><br/><pre id="a"></pre>
You can still find Martin's CJam version here.
Scoring
Your score is the area of your block of text (the width times the height). The submission with the lowest score wins. (Essentially the smallest code wins, hence the code-golf tag.) Tiebreaker goes to the earlier posted submission.
The example is 2 by 3 so its score is 6. A score less than 4 (2 by 2) is impossible because then some of the 8 programs would be identical and couldn't output two different values.
String.prototype.repeat()
is still kinda new. Also confirmed to work in IE now. new fiddle \$\endgroup\$