Since Halloween is coming up I thought I might start a fun little code golf challenge!

The challenge is quite simple. You have to write a program that outputs either trick or treat.
"The twist?" you may ask. Well let me explain:

Your program has to do the following:

  • Be compilable/runnable in two different languages. Different versions of the same language don't count.
  • When you run the program in one language it should output trick and the other should output treat. The case is irrelevant and padding the string with whitespace characters are allowed (see examples).
  • This is , so the solution with the fewest bytes wins.

A few explanations:

Valid outputs (Just for the words not for running the code in the two languages. Also adding quotes to signalize the beginning or end of the output. Do not include them in your solution!):



"    TReAt"

     tRICk          "

Invalid outputs:

"tri ck"



I'm interested to see what you can come up with! Happy Golfing!

I'd like to note that this is my first challenge so if you have suggestions on this question please leave them in the form of a comment.


Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

var QUESTION_ID=97472,OVERRIDE_USER=23417;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=o.replace(TAGS_REG,"")),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i,TAGS_REG = /(<([^>]+)>)/ig;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:400px;float:left}table thead{font-weight:700}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>

  • 21
    \$\begingroup\$ This meta answer states that near-duplicates can be tolerated if there's a good reason. I believe that the popularity this question receives from being close to Halloween is a good reason in itself, so I'll vote to reopen. I wouldn't mind closing it after Halloween (but I don't know if this would be a good thing either). \$\endgroup\$
    – Aaron
    Oct 26, 2016 at 14:57
  • 2
    \$\begingroup\$ @mbomb007. This is a duplicate of what? \$\endgroup\$
    – TRiG
    Oct 27, 2016 at 15:03
  • 3
    \$\begingroup\$ definitely not a duplicate. The only thing the same about that other one is that it's also a polyglot challenge with specified output. \$\endgroup\$ Oct 28, 2016 at 14:51
  • 3
    \$\begingroup\$ ... 3 pages... I really think that this is getting a lot of activity based on the current value of the seasonal variant. \$\endgroup\$
    – wizzwizz4
    Oct 29, 2016 at 10:09
  • 2
    \$\begingroup\$ What a great question! I love how some of the answers illuminate and exploit how simple code fragments mean different things in different languages-- e.g. truthiness/falsiness and associativity of the ternary operator. \$\endgroup\$
    – Don Hatch
    Nov 3, 2016 at 22:28

128 Answers 128


VBScript, JScript, 41 bytes

x="treat" rem=x="trick" WScript.echo(x)

The VBScript "rem" hides the JScript code.


Python 3 / JavaScript, 46 bytes

There weren't any "true" Python/JavaScript polyglot answers yet, so I figured I'd try my hand at writing one:


Python 3

This is how Python sees the code:


// is integer division in Python 3, so a=1//2; sets variable a to 0. Then alert=print sets the variable alert to the function print so that we can use alert to output.

In the next line, alert is called on the item at index a in the array ["trick","treat"]. Since a is 0 and alert is print, this prints "trick".


This is how JS sees the code:


The first line is parsed as a=1; the rest is simply a comment. This sets variable a to 1.

The second line, much like in Python, alerts the item at index a in ["trick","treat"]. Since a is 1, this alerts "treat".


Perl / Ruby : 41 bytes

#line 9
print __LINE__==2?"treat":"trick"

Lines beginning with # are comments in both Ruby and Perl. Except that lines following (roughly) the regex #\s*line\s+\d+ are executed by Perl's compiler and change the line number as the compiler sees it (see the doc : Plain Old Comments (Not!)).

So when arriving to the second line, Perl thinks it the 9th while Ruby thinks it's the second. Hence Ruby will print treat while Perl will print trick.

  • \$\begingroup\$ I did not know that was possible! Good to know... Shame it's not global: perl -E'eval"#line 9\nsay __LINE__";say __LINE__' \$\endgroup\$ Nov 2, 2016 at 9:16
  • \$\begingroup\$ @DomHastings I learned about it only a few days ago (I was bored so I went through the doc and found this :D ). Indeed, it would've been nice.. \$\endgroup\$
    – Dada
    Nov 2, 2016 at 9:39

PHP, Lua 41 Bytes

PHP print trick an Lua treat

  • \$\begingroup\$ You don't need the 2nd $a;. That is inside comment in both languages. \$\endgroup\$
    – manatwork
    Nov 1, 2016 at 9:00
  • \$\begingroup\$ You can join the 2nd and 3rd lines. And better check your count as currently I see there only 39 bytes. \$\endgroup\$
    – manatwork
    Nov 2, 2016 at 15:19

JavaScript (ES6) / Japt, 47 33 22 bytes



This should be fairly obvious: 1 and "treat" do nothing, and alert`trick` alerts trick.


In Japt, lowercase letters (except those in strings) transpile to method calls, e.g. .a(. However, if it comes after another lowercase letter, it is instead transpiled to "a". All open parentheses are cut off at semicolons ;. This means that the code roughly transpiles to:

1 .a("l".e("r".t("trick")));"treat"

This is then evaluated as JavaScript. "r".t("trick") is "r", "l".e("r") is "l", and 1.a("l") is 1. However, the poor JS engine's work is pointless: only the result of the last expression is sent to STDOUT, so the 1 is discarded and treat is printed.


CJam / HTML, 17 14 bytes


  • -3 bytes off. Thanks to @ETHProductions




TREAT           print TREAT
     <          tag open: ignore rest since there is no closing bracket


TREAT<         e#random stuff / push vars
      ;        e#discard stack
       "trick" e#literal trick
               e#implictly print
  • \$\begingroup\$ I think HTML is not considered a programming language. \$\endgroup\$
    – THC
    Oct 31, 2016 at 9:45
  • \$\begingroup\$ I think you can remove the !--. \$\endgroup\$ Nov 3, 2016 at 21:55
  • \$\begingroup\$ @FliiFe Lets say it's PHP. Would work too. \$\endgroup\$ Nov 6, 2016 at 12:43
  • \$\begingroup\$ @FliiFe you're allowed to use non-programming-languages in constant output challenges. \$\endgroup\$
    – Pavel
    Apr 24, 2017 at 1:58

////D1ffe7e45e, 59 bytes

See what I did there?


Basically, in D1ffe7e45e / begins and ends comments. So, TREAT is in a comment but the source that prints TRICK isn't. The __ is two no-ops to stop the D1ffe7e45e program from repeating. The source that /// interprets should be self-explanatory.

  • \$\begingroup\$ Well those comments disappeared o_O \$\endgroup\$
    – Timtech
    Oct 27, 2016 at 23:24
  • \$\begingroup\$ I don't think this works again. the /@/__/ is changed to //__/, so it doesn't halt \$\endgroup\$ Oct 27, 2016 at 23:27
  • \$\begingroup\$ (replace the first or second @ with something else) \$\endgroup\$ Oct 27, 2016 at 23:28
  • \$\begingroup\$ Yeah makes sense, this is my first time with this language ^_^ \$\endgroup\$
    – Timtech
    Oct 28, 2016 at 11:06

Emoji/Emojicode, 50 bytes


Try Emoji online!
Try Emojicode online!


Julia/Python, 31 Bytes

Nothing special, just taking advantage of the similarities between the languages. Julia uses 1 as the first index, while Python uses 0.


Try it online - Julia!

Try it online - Python!

  • \$\begingroup\$ Welcome to PPCG! Unless Julia does something I don't know, you can remove the extra spaces in the first line: list=["trick","treat"] and you can also rename list l to save some more bytes \$\endgroup\$
    – Stephen
    Aug 10, 2017 at 21:05
  • \$\begingroup\$ Welcome to PPCG, nice first golf! And you still haven't removed the space after , as far as I can tell. \$\endgroup\$
    – Adalynn
    Aug 10, 2017 at 21:21
  • \$\begingroup\$ Forgot about that one! Thanks! \$\endgroup\$
    – Rohan D
    Aug 10, 2017 at 21:24

Shakespeare Programming Language / Befunge-98, 467

"kcirt"4k,@.Puck,.Page,.Act I:.Scene I:.[Enter Page and Puck]Page:You is the sum of a big big big big big big cat and the sum of a big big big big cat and a big big cat.Speak thy mind!You is the sum of you and a big pig.Speak thy mind!Puck:You is the sum of me and the sum of a big big big pig and the sum of a big big pig and a pig.Speak thy mind!You is the sum of you and a big big pig.Speak thy mind!Page:You is the sum of you and a big cat.Speak thy mind![Exeunt]

Try it online: Shakespeare Programming Language / Befunge-98

Befunge-98 prints trick, Shakespeare prints TREAT.


Befunge executes until the @, so the SPL program is ignored. In SPL, everything until the first dot is ignored because it's the title.

Edit: port the answer to the official SPL interpreter - I couldn't get it to work before.


Scala / Javascript, 33 bytes

if(0==false)"trick"; else "treat"

0==false returns true in javascript, but false in scala


Befunge-98/DOS .COM file, 27 bytes

00000000  22 20 b4 09 ba 0b 01 cd  21 c3 20 74 72 65 61 74  |" ......!. treat|
00000010  24 6b 63 69 72 74 22 34  6b 2c 40                 |$kcirt"4k,@|

The Befunge-98 part pushes the characters of a string to the stack, and then outputs the top 5 characters in the stack and ends.

The DOS part is:

00000000  2220              and ah,[bx+si]
00000002  B409              mov ah,0x9
00000004  BA0B01            mov dx,0x10b
00000007  CD21              int 0x21
00000009  C3                ret

Where the first instruction is just some dummy non important instruction, and the rest calls INT 21h function 09h, which prints a $-terminated string pointed to by DS:DX.


Charcoal and Pip, 13 bytes



Charcoal's code page reads this as trickΒ»"treat". trick prints the string to the canvas. Β» closes a block; apparently, if it is unmatched, it ends the program. The canvas is then printed to the screen.

Try it online


t              Variable (no-op)
 r             Generate random number (and do nothing with it)
  i            Variable (no-op)
   c           Variable (no-op)
    k          Variable (no-op)
     Β©         Unrecognized character, ignored
      "treat"  String, output implicitly

Try it online


C/Lua, 65 bytes


Ruby / ECMA6 27 bytes


Turns out you don't need to assign a JSON object in oredr to use it in ecma6

Original, with plain Javascript:

Ruby/Javscript 32 31 bytes


Because ruby treats the key as as symbol (:t), does not match with 't' so goes to the or. Whereas JavaScript is not as fussy.

  • \$\begingroup\$ Cool trick! I'm not sure if this qualifies as a full program/function though :(. \$\endgroup\$
    – m-chrzan
    Oct 27, 2016 at 13:40

Python/Brainf**k (87 Bytes)


Python ignores everything after the # because its a comment and brainf**k ignores print("treat")# because they are unrecognized characters.


Forth/Perl, 53 bytes

1 ?dup : print"trick" ." treat" ; print"trick" or bye

Needs a case-insensitive Forth (e.g: GNU Forth).

When run in Forth, it defines a print"trick" word that outputs "treat", then calls it.

When run in Perl, it uses the colon of Forth's word definition as part of a conditional statement. In ?dup, the question mark forms part of the aforementioned conditional statement, and dup gets treated as a bareword (a string without quotes). The dot in Forth's ." primitive gets interpreted as Perl's concatenation operator, and bye gets treated as another bareword.


C / C++, 72 bytes


Compile with gcc/g++ -ansi and don't regard warnings. A C90-conforming C compiler does not recognize // as a comment but it skips /**/, leaving puts(a[1/2]);. C++ will see puts(a[1]);.


Bash / Wolfram Language (a.k.a. Mathematica), 19 bytes

echo trick;#&@treat

For Bash, # is a comment indicator so it just outputs trick. Mathematica multiplies two undefined symbols echo and trick but ignores the result and proceeds to the second command, which fully expanded goes


and evaluates to treat.


C / Javascript, 70 47 bytes

(excluding comments C=22 + Javascript=14 ~= 36 )


What C sees:


What javascript sees:



/* C comment ends with '/' on next line but js comment remains open  *\ 
/ //BEGIN C Block 
#define function int 
//*/alert("this whole line is commented in C, but // is in the js comment")

//for additional tricks...
/*Most compilers can build K&R style C with parameters like this:*/ 
function volume(x,y,z)/**\ 
/int x,y,z;/**/ 
  return x*y*z; 

#undef function 
#define var const char** 
#define new (const char*[]) 
#define Array(...)  {__VA_ARGS__} 

var cars = new Array("Ford", "Chevy", "Dodge"); 

/* Or a more readable version *\ 
/// BEGIN C Block 
#undef var 
#undef new 
/* END C Block */ 

Windows Batch, JScript, 35 bytes

trick="treat";WScript. echo (trick)

The batch version displays the parentheses as delimiters.

  • \$\begingroup\$ This outputs (trick) instead of trick. \$\endgroup\$ Oct 30, 2016 at 5:24
  • \$\begingroup\$ yes, the batch version displays the parentheses as delimiters. \$\endgroup\$ Nov 1, 2016 at 19:50
  • \$\begingroup\$ Actually, batch displays whatever you write after. In this case, it will show (trick). If you wrote "trick", it would show that. \$\endgroup\$ Nov 1, 2016 at 23:32
  • \$\begingroup\$ but then it won't be valid JavaScript, which requires the parentheses to run the function. \$\endgroup\$ Nov 2, 2016 at 16:45
  • \$\begingroup\$ Can you use backticks? \$\endgroup\$ Nov 2, 2016 at 18:16

Ruby / Crystal, 31 bytes

puts 'a'=="a"&&"trick"||"treat"

'a' is a string literal in Ruby and a character literal in Crystal. "a" is a string literal in both. This abuses that difference to detect the language the script is ran in.


Pyth and SMBF, 28 bytes


"trick" explanation:

Pyth has a quit-type operation with .q, which I use at <.q to end the program. Everything afterwards is uninterpreted, but in order for me to fix arity I need to add arity 0 data after each arity-2 <. Otherwise, the program requires user input (although what Python datum the input wouldn't matter, since it's not used). Pyth will implicitly print the "trick" at the beginning of the program.

"treat" explanation:

The only characters that SMBF uses are as follows (the others are no-ops or not examined in memory): "<.<.<.<.<.taert. The <. sets print out the last five characters of the program in reverse order (hence treat is reversed into taert to have it print as treat).

  • 2
    \$\begingroup\$ I appreciate the game you've set up, but can you remove the spoiler from the title please? :) \$\endgroup\$
    – Beta Decay
    Oct 28, 2016 at 6:09

Actually and Python 2, 21 bytes

thanks to quartata for this solution


Try it online: Actually, Python 2



print                  5 NOPs (they only do things if the stack isn't empty)
     "trick"           push "trick"
            #          listify
             X         discard (stack is now empty)
              "treat"  push "treat"
                       (implicitly print)

Python 2:

print"trick"           # print "trick"
            #X"treat"  # a comment
  • 1
    \$\begingroup\$ print"trick"#X"treat" is shorter but much more boring. \$\endgroup\$ Oct 31, 2016 at 20:45

Windows Batch, VBScript, 34 bytes

echo trick

The Batch echo will display the immediate text.
The VBScript uses the "_" line-continuation to run the "echo" command, which displays the contents of the variable "trick", which contains the string "treat".
VBScript does not require parenthesis for functions which do not return a value.

  • \$\begingroup\$ Can you explain how this works ? \$\endgroup\$
    – THC
    Oct 31, 2016 at 9:42
  • \$\begingroup\$ @FliiFe, updated my answer. \$\endgroup\$ Nov 1, 2016 at 19:55

HTML / JavaScript (ES6), 28 bytes

trick<alert`treat`;var trick

Test HTML | Test JS


HTML is a lot like ///: it writes out any plain text, ignoring anything after a < until it gets to a >. Since there are no >s, it just writes "trick".

JS is simple: alert`treat`. However, to avoid a ReferenceError for trick not being defined, we have to add a var trick to tell JS that trick is really supposed to be there.

I wanted to add CSS that "prints" or, but it seems to be impossible:

  • If the CSS is before the <, it gets written to the HTML document.
  • If the CSS is after the <, it finds a syntax error and stops before running.

Haskell / Ruby, 74 bytes

main=if True then print "trick" else print "treat";--0;end


Anything starting with -- is treated as a comment. Actual program in Haskell is now just

main=if True then print "trick" else print "treat";

which prints "trick".


--0 is just -(-0). So the first line declares a constant True with a value false. Next line does the actual printing and since True is false, it prints "treat". main is just treated as a variable in ruby and is assigned the value 0.

  • \$\begingroup\$ Welcome to the site! \$\endgroup\$
    – DJMcMayhem
    Nov 3, 2016 at 16:14

sh / csh, 32 bytes

echo trick #treat|sed 's/.*#//'

For csh, the command must be executed interactively.

Explanation: In interactive mode, sh treats anything starting with # as a comment. csh does so only in batch mode.

ksh and bash behave the same way as sh. tcsh behaves like csh. Some of these shells have options to alter this behavior.

zsh behaves like csh for this particular command.

  • 1
    \$\begingroup\$ bash has interactive_comments shopt` and zsh has INTERACTIVE_COMMENTS to control this behaviour. \$\endgroup\$
    – ninjalj
    Nov 3, 2016 at 1:28

C / C++, 73 bytes

int main(){puts("treat\0trick"+sizeof'1'/sizeof 1*6);}

This could fail (printing trick in both C and C++) on an implementation with sizeof (int) == 1, which implies CHAR_BIT >= 16. As far as I know there are no such implementations in the real world.

Changing int main() to int main(void) would make it theoretically more conforming in C, but in practice all C and C++ compilers accept int main().

  • 1
    \$\begingroup\$ We don't really require portability here; as long as it works in one implementation that predates the challenge, it's valid. With gcc/g++ and the right OS/architecture, you can replace include with import, remove int and replace sizeof 1*6 with 2*3. \$\endgroup\$
    – Dennis
    Nov 3, 2016 at 20:34

Labyrinth/Perl, 38 bytes

As cat -v:


Where ^@ represents ASCII 0 (␀), ^B represents ASCII 2 (␂), ^L represents ASCII 12 (␌), and ^_ represents ASCII 31 (␟). Or, as a hexdump -C:

00000000  24 5f 3d 31 31 36 2e 31  31 34 2e 31 30 35 2e 39  |$_=|
00000010  39 2e 31 30 37 2e 24 40  5e 22 00 00 0c 02 1f 22  |9.107.$@^"....."|
00000020  3b 70 72 69 6e 74                                 |;print|

I have wanted to post a Labyrinth/Perl answer since reading Emigna's Labyrinth/><> answer. In that answer, Labyrinth code looks very much like it starts with a Perl version string.

So, in this answer, Labyrinth just does the following:

$_=                    β†’ dummy operations    β†’ print string
$                      β†’ dummy op
@                      β†’ end

while Perl does:

$_=                    β†’ set the $_ variable to:    β†’  a version string for the other language
 .$@                   β†’  concatenated with $EVAL_ERROR (null when no eval error)
 ^"^@^@^L^B^_";        β†’  XORed with "\0\0\x0c\2\x1F", to get "treat" from "trick"
print                  β†’ and finally print the string

Labyrinth/Perl alternate version, 105 bytes

Here is another version, modifying the string in Labyrinth code, instead of in Perl code:

; $_=$@
; ;print;      1+ 7+ 16
; ;;;;;;;;;;;;; 1
;              ;;
;;;;;9^_9^10^00 ^a

Labyrinth code follows the path. The last line modifies the code, rotating columns using ^. After the last line has been interpreted, the field looks like:

; $_=$@
; ;     ;       +  +      
; ;;;;;;;;;;;;;;1         
;               ;         
;;;;;9^_9^10^005^ 9  07   

After finishing interpreting the last line, Labyrinth follows the path upwards. Then, the 1 makes it attempt to turn rightwards, but hitting the wall makes it turn leftwards instead. Afterwards, Labyrinth just follows the path, eventually reaching code already explained for the first approach (where Perl modifies the string).

As you'll notice, (in 9^_9^10^00 ^ 1) numbers in Perl can have _ in them, to make them more readable.

Labyrinth/Perl, linear labyrinth version, 76 bytes

Not as fun as the previous one, but does the trick (or treat, as it may be):

        ; print$    ;   ;  1+ 7+ 16

Labyrinth/Perl, boring version, 49 bytes

Separate code paths for Labyrinth and Perl:


Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.