Choose-Your-Own-Language Code

17

Let's take a grid of 16x16 printable ASCII characters (code points 0x20 to 0x7E). There are 30-choose-15 paths from the top left to the bottom right corner, making only orthogonal moves, like the following example:

##..............
.#..............
.######.........
......##........
.......##.......
........#.......
........#.......
........#.......
........###.....
..........###...
............#...
............####
...............#
...............#
...............#

Each such path consists of exactly 31 characters. Note that each of those characters is on a different of the 31 anti-diagonals:

0123456789ABCDEF
123456789ABCDEFG
23456789ABCDEFGH
3456789ABCDEFGHI
456789ABCDEFGHIJ
56789ABCDEFGHIJK
6789ABCDEFGHIJKL
789ABCDEFGHIJKLM
89ABCDEFGHIJKLMN
9ABCDEFGHIJKLMNO
ABCDEFGHIJKLMNOP
BCDEFGHIJKLMNOPQ
CDEFGHIJKLMNOPQR
DEFGHIJKLMNOPQRS
EFGHIJKLMNOPQRST
FGHIJKLMNOPQRSTU

This is not an example grid. This is a visualisation of the 31 anti-diagonals.

We'll call a grid diagonally unique if no anti-diagonal contains the same character twice. If the grid has this property, no two paths will contain the same string. (Just to clarify, the visualisation itself is basically the opposite of diagonally unique.)

The Challenge

Design a diagonally unique 16x16 grid, such that as many paths as possible are valid code which prints Jabberwocky to STDOUT (with optional trailing line break) in as many languages as possible. Each code may either be a full program, or the body of a parameterless function without return statement (this is in order not to discourage languages that need to have their code in some boilerplate function/class/namespace).

Note: For simplicity you can use some reserved character for unused cells like Ypnypn did.

For each valid path, please clearly state one programming language it is valid in.

The winner is the submission with the largest number of languages covered by the above list. (Alternatively, for each language you want to count, show one path which is valid in that language, but make sure not to count any path for two languages.)

In the event of a tie, count the grid cells which are not covered by any valid path. Fewer unused cells win. If there is still a tie, I'll accept the answer with the most (net) votes.

Validation Script

I just quickly put together a little CJam snippet you can use to validate that a grid is diagonally unique.

  1. Go to the online CJam interpreter.
  2. Paste the following code

    l:A;
    qN/W%A16**33/z{A-__|=}%:*"D""Not d"?"iagonally unique"
    
  3. In the input field, put you reserved character on the first line (use an unused character if you don't make sue of a reserved character), and then your grid in line 2 to 17. E.g., for Ypnypn's answer:

    ~
     pr~~~~~~~~~~~~~
     tin~~~~~~~~~~~~
    ~ypt(~~~~~~~~~~~
    ~~ef(~~~~~~~~~~~
    ~~  "J~~~~~~~~~~
    ~~~~~ab~~~~~~~~~
    ~~~~~~be~~~~~~~~
    ~~~~~~~rwo~~~~~~
    ~~~~~~~~~ck~~~~~
    ~~~~~~~~~~y~~~~~
    ~~~~~~~~~~\n~~~~
    ~~~~~~~~~~~")) ~
    ~~~~~~~~~~~  ;  
    ~~~~~~~~~~~~~~~ 
    ~~~~~~~~~~~~~~~ 
    ~~~~~~~~~~~~~~~ 
    
  4. Run.

Let me know if you think it has a bug.

Martin Ender

Posted 2014-10-27T22:54:50.290

Reputation: 184 808

6'Twas brillig, and the slithey toves did gyre and gimble in the wabe... (yes, I have that memorized) ;) – Doorknob – 2014-10-28T00:08:39.673

This sounds like one of Calvin's Hobbies' questions, which is a fantastic achievement. I still have not been able to understand how it's done. – Soham Chowdhury – 2014-10-29T17:39:24.777

Answers

21

30 33 35 Languages

Reserved character: ~

 println!~~~~~~~
 puts    (1,~~~~
    echo   '~~~~
"cWprintfn"Ja~~~
Eork~~~;'Jabbe~~
\ui)K00~~~~~br~~
]tteL~0~~~~~ew~~
]<~ln(0~~~~~ro~~
`<~~~ 0~~~~~wc~~
m"~~~ "~~~~~ok~~
rJ~~~'J~~~~~cy~~
j"<< "a~~~~~k'..
^~~~~~bberwoy");
f~~~~~~~~~~c'  ;
t~~~~~~~~~~ky"  
XX"););  5f+'); 

Languages:

01. Rust        | println! (  "Jabberwocky") ;  |
02. Groovy      | println     "Jabberwocky"     |
03. E           | println  (  "Jabberwocky")    |
04. Swift       | println  (  "Jabberwocky") ;  |
05. Julia       | println  (  "Jabberwocky");;  |
06. Processing  | println  (  "Jabberwocky")  ; |
07. Falcon      | printl   (  "Jabberwocky")    |
08. ALGOL 68    | print    (  "Jabberwocky")    |
09. Vala        | print    (  "Jabberwocky") ;  |
10. Pawn        | print    (  "Jabberwocky");;  |
11. Batsh       | print    (  "Jabberwocky")  ; |
12. freeBASIC   | print       "Jabberwocky"     |
13. Rebol       | print       "Jabberwocky"  ;  |
14. Red         | print       "Jabberwocky"   ; |
15. AWK         | print       'Jabberwocky'     |
16. Perl        | print       'Jabberwocky'  ;  |
17. bc          | print       'Jabberwocky'   ; |
18. Euphoria    |  puts    (1,"Jabberwocky")    |
19. C           |  puts    (  "Jabberwocky") ;  |
20. Tcl         |  puts       "Jabberwocky"     |
21. Ruby        |  puts       'Jabberwocky'     |
22. Zsh         |      echo   "Jabberwocky"     |
23. Bash        |      echo   "Jabberwocky"  ;  |
24. tcsh        |      echo   "Jabberwocky"   ; |
25. PHP         |      echo   'Jabberwocky'     |
26. Fish        |      echo   'Jabberwocky'  ;  |
27. Dash        |      echo   'Jabberwocky'   ; |
28. F#          |      printfn"Jabberwocky"   ; |
29. C++         |    cout<<"J"<< "abberwocky" ; |
30. D           |     Writeln(  'Jabberwocky'); |
31. Pascal      |     WriteLn(  'Jabberwocky'); |
32. Delphi      |     Writeln(  "Jabberwocky"); |
33. GolfScript  |      print;'Jabberwocky'..;;  |
34. CJam        |   "E\]]`mrj^ftXX"););  5f+'); |
35. Pyth        |      pk)K00000"Jabberwocky"   |

(Pyth and CJam thanks to user23013)

Optimizer

Posted 2014-10-27T22:54:50.290

Reputation: 25 836

Added CJam and Pyth. – jimmy23013 – 2014-12-22T15:15:11.180

@user23013 I modified the CJam one and chose a bit different approach. Thanks for both of them! – Optimizer – 2014-12-22T20:59:40.593

The Swift solution is not valid anymore. It is now print(...). You can specify the version (i.e: Swift 1.0) which would be valid – Mr. Xcoder – 2017-04-04T13:03:51.573

Actually, the haskell code prints the string with quotation marks. To print it without them you would need putStr[ln].... Also, haskell doesn't have ;;. I believe you mixed it with Ocaml. – proud haskeller – 2014-10-29T21:40:09.197

Even Ocaml doesn't have that. (The online interpreter gives error if I put ;;). Anyways, replaced Haskell with something else. – Optimizer – 2014-10-29T22:05:19.223

Pyth would be easy to add - | p b"Jabberwocky" | works, for instance – isaacg – 2014-10-30T16:45:16.663

@isaacg Thanks! I was going to look into Pyth too. This saves me time :) – Optimizer – 2014-10-30T16:50:46.580

@isaacg BTW, where is such path ? – Optimizer – 2014-10-30T16:51:54.240

Use the P in coWprint, add spaces and a b down to the lower Jabberwocky. – isaacg – 2014-10-30T16:54:28.270

Can't add space in that path before that existing " – Optimizer – 2014-10-30T16:55:29.047

Why not? It seems open to me. – isaacg – 2014-10-30T18:09:24.427

unique characters in anti sub diagonals. – Optimizer – 2014-10-30T18:18:16.980

15

17 languages

Here's the grid, with . as the reserved character:

 prin...........
 utstln!........
       (1,......
<?echo    ".....
.........'Jab...
............b...
............e...
............r...
............w...
............o...
............c...
............k...
............y"..
............' ).
.............  ;
..............  

And here are the languages and their paths (ignore the vertical bars):

01. Rust        | println!(   "Jabberwocky" ) ; |
02. Swift       | println (   "Jabberwocky" ) ; |
03. Scala       | println (   "Jabberwocky" )   |
04. Falcon      | printl  (   "Jabberwocky" )   |
05. Vala        | print   (   "Jabberwocky" ) ; |
06. Lua         | print   (   'Jabberwocky' ) ; |
07. ALGOL 68    | print   (   "Jabberwocky" )   |
08. Dart        | print   (   'Jabberwocky' )   |
09. Rebol       | print       "Jabberwocky"   ; |
10. Perl        | print       'Jabberwocky'   ; |
11. AWK         | print       "Jabberwocky"     |
12. Euphoria    | puts    (1, "Jabberwocky" )   |
13. C           | puts    (   "Jabberwocky" ) ; |
14. Tcl         | puts        "Jabberwocky"     |
15. Ruby        | puts        'Jabberwocky'     |
16. Bash        |     echo    "Jabberwocky"     |
17. PHP         |     echo    "Jabberwocky"   ; |

I haven't been able to test all of them, so let me know if something doesn't work.

grc

Posted 2014-10-27T22:54:50.290

Reputation: 18 565

I think you cannot use the same path for more than one language and add it to your score. – Optimizer – 2014-10-28T10:58:55.523

1@Optimizer I don't think there are any paths used twice. Admittedly, the differences are pretty small. – grc – 2014-10-28T11:00:12.680

1Ugh, you sneaky guy! :P – Optimizer – 2014-10-28T11:24:10.450

For PHP, after removing boilerplate, echo "foobar" (more than 1 space each time) prints just fine. Without any white spaces. Try it here

– Optimizer – 2014-10-28T19:30:36.967

@Optimizer The problem is the space before <?. But you can probably omit that altogether if you invoke the script with the PHP interpreter itself from the command line, but I'm not sure. – Martin Ender – 2014-10-28T19:40:20.830

2Its okay to remove boilerplate from the code, which is <? here – Optimizer – 2014-10-28T19:41:10.973

@Optimizer Lol right, forgot my own rules. – Martin Ender – 2014-10-28T21:18:34.877

@Optimizer Thanks! I forgot <? counts as boilerplate. – grc – 2014-10-28T22:13:01.753

Why do you have <? – proud haskeller – 2014-10-29T16:24:51.953

@proudhaskeller it was originally for PHP and I haven't bothered to remove it. – grc – 2014-10-29T21:23:10.350

3

18 languages and more

Reserved character: ~.

         "~~~~~~
12345678 "~~~~~~
12345678 "~~~~~~
12345678 "~~~~~~
1234567: ea~~~~~
1234567: c;~~~~~
1234567: hL~~~~~
1234567: o'~~~~~
1234567:  Jab~~~
1234567:?""""~~~
~~~~~~~~~Jabberw
~~~~~~~~~~~~~~~o
~~~~~~~~~~~~~~~c
~~~~~~~~~~~~~~~k
~~~~~~~~~~~~~~~y
~~~~~~~~~~~~~~~"

Languages:

CJam                             |             ea;L'J"abberwocky"|
GolfScript                       |              cho "Jabberwocky"|
Bc                               |                  "Jabberwocky"|
Bash                             |         """"echo J"abberwocky"|
Zsh                              |           ""echo J"abberwocky"|
Fish                             |             echo J"abberwocky"|
Tcsh                             |         """"echo Ja"bberwocky"|
Dash                             |           ""echo Ja"bberwocky"|
Ksh                              |             echo Ja"bberwocky"|
Mksh                             |         """"echo Jab"berwocky"|
Yash                             |           ""echo Jab"berwocky"|
Sash                             |             echo Jab"berwocky"|
Posh                             |         """"echo "Jabberwocky"|
Csh                              |           ""echo "Jabberwocky"|
PHP                              |             echo "Jabberwocky"|

and...

FreeBasic                        |                 ?"Jabberwocky"|
QBasic                           | 12345678        ?"Jabberwocky"|
QB64                             | 123456788       ?"Jabberwocky"|

There should be many more Basic dialects that works. But I don't have time to test all of them yet.

jimmy23013

Posted 2014-10-27T22:54:50.290

Reputation: 34 042

Remember that you cannot use the same path for more than 1 language. So not all BASIC dialects will fit in. – Optimizer – 2014-12-23T08:50:09.123

2@Optimizer At least those dialects which have line numbers and doesn't check overflow (and have ? for print) should work... Just select a different line number. – jimmy23013 – 2014-12-23T08:54:56.193