Trick or Treat polyglot

162

30

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!):

"trick"

"Treat"

"    TReAt"

"
     tRICk          "

Invalid outputs:

"tri ck"

"tr
eat"

"trck"

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.

Leaderboards

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>

BrainStone

Posted 2016-10-25T23:57:54.160

Reputation: 1 501

21This 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). – Aaron – 2016-10-26T14:57:17.787

Does a null byte (0x00) count as white space? – Riley – 2016-10-27T12:11:32.397

@Riley I'll say yes. – BrainStone – 2016-10-27T12:12:13.830

2@mbomb007. This is a duplicate of what? – TRiG – 2016-10-27T15:03:13.157

3definitely not a duplicate. The only thing the same about that other one is that it's also a polyglot challenge with specified output. – Brian Minton – 2016-10-28T14:51:23.130

This would also have been a fun one as a code challenge instead of golf. – Brian Minton – 2016-10-28T14:55:06.260

@BrianMinton Which type of code challenge, i.e., which winning criterion, do you have in mind? – Dennis – 2016-10-28T19:04:31.227

1actually, looking at the tags, I think that what I was thinking of was just popularity-contest. – Brian Minton – 2016-10-28T20:30:52.440

3... 3 pages... I really think that this is getting a lot of activity based on the current value of the seasonal variant. – wizzwizz4 – 2016-10-29T10:09:40.040

The leaderboard doesn't work for me; it only shows the top 10 overall answers, and none of the Winners by Language. – ETHproductions – 2016-11-02T00:52:09.600

@Oliver do you know why the leaderboard doesn't work? – BrainStone – 2016-11-03T18:57:30.720

2What 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. – Don Hatch – 2016-11-03T22:28:58.863

Answers

148

2sable / pl, 8 bytes

0000000: 74 72 65 61 74 93 d0 cb                          treat...

Both programs have been tested locally with the same 8 byte file, so this is a proper polyglot.

2sable: trick

This is the program in code page 1252.

treat“ÐË

Try it online!

pl: treat

This is the program in code page 437.

treatô╨╦

Try it online!

How it works

2sable: trick

t         Square root. Errors since there is no input. The exception is caught, the
          stack left unaltered, and the interpreter pretends nothing happened.
 r        Reverse stack.
          Reversed empty stack is still empty stack. ;(
  e       Compute nCr. Errors since there is no input.
   a      Alphanumeric test. Errors since there is no input.
    t     Square root. Errors since there is no input.
     “    Begin a lowercase string literal.
      Ð     Excluding ‘, ’, “, and ”, Ð is the 71st non-ASCII character in CP1252.
       Ë    Excluding ‘, ’, “, and ”, Ë is the 66th non-ASCII character in CP1252.
          (implicit) End string literal.
          Both characters together fetch the dictionary word at index
          71 * 100 + 66 = 7166, which is 'trick'.

pl: treat

treat     Bareword; push the string "treat" on the stack.
     ô    Unimplemented. Does nothing.
      ╨   Flatten the stack. This doesn't affect the output.
       ╦  Unimplemented. Does nothing.

Dennis

Posted 2016-10-25T23:57:54.160

Reputation: 196 637

16But I've got to admit this answer is plain ridiculous! What's next? An answer that's shorter than the words themself? – BrainStone – 2016-10-26T19:50:54.077

46This answer is extremely impressive. It's amazing that you managed to write a program shorter than the length of the two words. – James – 2016-10-26T21:20:22.037

1Huh? Those are 2 programs – FireCubez – 2018-10-25T18:19:07.207

3@FireCubez It's the same code, byte per byte. The visual representation varies with the codepage though. – Dennis – 2018-10-25T18:27:24.440

201

Python / Windows Batch, 25 bytes

print"trick"#||echo.treat

Everything after the # is interpreted as a comment by python, while the || is an OR in batch, saying that as the previous command failed, execute this one.

I also like the use of an OR as it almost reads "trick or treat" :)

nephi12

Posted 2016-10-25T23:57:54.160

Reputation: 1 691

33TBH I up-voted this just for the comment about the OR. – Jmons – 2016-10-26T10:07:37.080

7TBH I never ever expected my first post here to get 65 upvotes :) – nephi12 – 2016-10-27T15:54:52.320

11TBH lets not just talk about upvotes. Its not Quora – S Andrew – 2016-10-28T10:13:37.570

3@SAndrew as a brand new member of this community, i didnt expect to make a post that would be this well recieved this soon, and i'm happy to have been able to contribute. I'm not trying to brag, please don't misunderstand. I'm just really happy to be so well recieved as i'm so new. thanks for you're comment :) – nephi12 – 2016-10-29T15:39:27.287

1@nephi12 I have tried running your code, but it doesn't seem to work. Running it on Python, as expected, runs flawlessly. But in a bat file, it just writes 'print"trick"#' is not recognized as an internal or external command, operable program or batch file. However, this version has worked for me: print "trick"#|echo.treat - piping the output to the echo – Yotam Salmon – 2016-10-29T15:43:45.030

@YotamSalmon double check that a "treat" isn't output after the error, as that is the function of an OR in batch. also, i'm not on windows right now, but i think i tried the pipe and it didnt work... are you running this in a script or on the prompt? – nephi12 – 2016-10-29T15:47:04.197

@nephi12 No "treat" is printed after the error. I'm running it from a bat script. What windows do you use? I'm using windows 7. However, if replacing the || operator with a pipe (|) works for you (when you're in front of a windows computer, try it out), it can save you a byte ;-) – Yotam Salmon – 2016-10-29T15:50:22.770

huh, i'll look into it. not sure why it doesn't work for you as is though. – nephi12 – 2016-10-29T15:53:10.483

2@YotamSalmon community consensus says that STDERR is ignored by default; only STDOUT is considered. Try the command again with 2>nul. – Conor O'Brien – 2016-10-30T14:57:18.920

@ConorO'Brien Oh, cool! Didn't know that. Thanks for informing me! – Yotam Salmon – 2016-10-30T15:12:18.227

1@SAndrew quora stopped caring about upvotes for a long time. Stack exchange does – phuclv – 2016-11-01T03:20:31.653

1It's been several months since your first post now but I just found it and I want to say that we are now avatar buddies. </chat> – Engineer Toast – 2017-04-26T17:39:15.783

157

Whitespace / Starry, 135 bytes

Here's to a clear night sky on Halloween!

  + +    +      + + 
    +

* +   +*      +     *

   +    *           
     + +        

 +* +   



 +* + .  + .   +      +* +   +* . . .

Note that whitespace on empty lines may not be preserved if you copy from the above code

Whitespace outputs "TRICK". Try it Online!
Starry outputs "TREAT". Try it Online!

Explanation

Starry

Starry ignores all tabs and new lines so the code it reads is the following

         + + + + + +  * +   +*   +  *   +  *       + +   +* +   +* + .  + .   +      +* +   +* . . .

Bytewise, pushing values is very expensive compared to stack and arithmetic operations in Starry. The code starts by pushing and duplicating 4 and the performs a number of operations on it and with 2 and 1 pushed later on produces all of the required ASCII values.

Annotated Code

Stack (after op)    Code        Operation
4                            +  Push 4
4 4 4 4 4 4          + + + + +  Duplicate top of stack 5 times
4 4 4 4 16            *         Multiply top two items
4 4 4 4 16 16        +          Duplicate top of stack
4 4 4 16 4 16          +        Rotate top three items on stack right
4 4 4 16 20         *           Add top two items
4 4 20 4 16            +        Rotate...
4 4 20 64             *         Multiply...
4 64 4 20              +        Rotate...
4 64 80               *         Multiply...
4 64 80 2                  +    Push 2
4 64 80 2 2          +          Duplicate...
4 64 2 80 2            +        Rotate...
4 64 2 82           *           Add...
4 64 2 82 82         +          Duplicate...
4 64 82 2 82           +        Rotate...
4 64 82 84          *           Add...
4 64 82 84 84          +        Rotate...
4 64 82 84           .          Pop and print as character (T)
4 64 84 82            +         Swap top two items on stack
4 64 84              .          Pop and print... (R)
84 4 64                +        Rotate...
84 4 64 1                 +     Push 1
84 4 65             *           Add...
84 4 65 65           +          Duplicate...
84 65 4 65             +        Rotate...
84 65 69            *           Add...
84 65                .          Pop and print... (E)
84                   .          Pop and print... (A)
                     .          Pop and print... (T)

Whitespace

As the name may suggest, Whitespace only parses the three whitespace characters—space, tab, and newline. Unlike the Starry, the Whitespace simply pushes the ASCII values of T, R, I, C, and K and the prints them.

Annotated Code

<Space><Space><Space><Tab><Space><Tab><Space><Space><Tab><Space><LF> Push the ASCII value of R
<Space><Space><Space><Tab><Space><Tab><Space><Tab><Space><Space><LF> Push the ASCII value of T
<Tab><LF><Space><Space> Pop and print the T
<Tab><LF><Space><Space> Pop and print the R
<Space><Space><Space><Tab><Space><Space><Tab><Space><Space><Tab><LF> Push the ASCII value of I
<Tab><LF><Space><Space> Pop and print the I
<Space><Space><Space><Tab><Space><Space><Tab><Space><Tab><Tab><LF>   Push the ASCII value of K
<Space><Space><Space><Tab><Space><Space><Space><Space><Tab><Tab><LF> Push the ASCII value of C
<Tab><LF><Space><Space> Pop and print the C
<Tab><LF><Space><Space> Pop and print the K
<LF><LF><LF>            Terminate the program. The following line is not run.
<Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><Space><LF>

The interweaving of pushes and prints was chosen based solely on aesthetic reasons as it does not affect the byte count.

0 '

Posted 2016-10-25T23:57:54.160

Reputation: 3 439

12so beautiful sky – lois6b – 2016-10-26T07:14:40.040

9this is by far the best answer, so creative. im shocked by the ingenuity. and the skill. bravo! – nephi12 – 2016-10-27T05:16:31.373

139

Linux ELF x86 / DOS .COM file, 73 bytes

00000000  7f 45 4c 46 01 00 00 00  1a 00 00 00 1a 00 43 05  |.ELF..........C.|
00000010  02 00 03 00 1a 00 43 05  1a 00 43 05 04 00 00 00  |......C...C.....|
00000020  eb 0c b4 09 ba 41 01 cd  21 c3 20 00 01 00 b2 05  |.....A..!. .....|
00000030  b9 3b 00 43 05 cd 80 2c  04 cd 80 74 72 69 63 6b  |.;.C...,...trick|
00000040  00 74 72 65 61 74 24 eb  d9                       |.treat$..|
00000049

NASM source:

ORG 0x05430000

BITS 32                                         ;
                                                ;   ELF HEADER    --   PROGRAM HEADER
; ELF HEADER                                    ; +-------------+
DB 0x7f,'E','L','F'                             ; | magic       |    +--------------------+
                                                ; |             |    |                    |
; PROGRAM HEADERS                               ; |             |    |                    |
DD 1                                            ; |*class 32b   | -- | type: PT_LOAD      |
                                                ; |*data none   |    |                    |
                                                ; |*version 0   |    |                    |
                                                ; |*ABI SysV    |    |                    |
DD 0x01a        ; offset = vaddr & (PAGE_SIZE-1); |*ABI vers    | -- | offset             |
                                                ; |             |    |                    |
entry:  DD 0x0543001a                           ; |*PADx7       | -- | vaddr = 0x0543001a |
DW 2                                            ; | ET_EXEC     | -- |*paddr LO           |
DW 3                                            ; | EM_386      | -- |*paddr HI           |
DD 0x0543001a                                   ; |*version     | -- | filesz             |
;       inc     ebx     ; STDOUT_FILENO         ; |             |    |                    |
;       mov     eax, 4  ; SYS_WRITE             ; |             |    |                    |
DD 0x0543001a                                   ; | entry point | -- | memsz              |
DD 4                                            ; | ph offset   | -- | flags: RX          |
                                                ; |             |    |                    |
        jmp     short skip                      ; |*sh offset   | -- |*align              |
BITS 16                                         ; |             |    |                    |
treat:  mov     ah, 9                           ; |             | -- |                    |
        mov     dx, trick + 0x100 + 6           ; |*flags ______|    |                    |
        int     0x21                            ; |______/      |    +--------------------+
        ret                                     ; |*ehsize      |
BITS 32                                         ; |             |
DW 32                                           ; | phentsize   |
DW 1                                            ; | phnum       |
skip:                                           ; |             |
        mov     dl, 5   ; strlen("trick")       ; |*shentsize   |
        mov     ecx, trick                      ; |*shnum       |
                                                ; |*shstrndx    |
                                                ; +-------------+
        int     0x80
        sub     al, 4   ; SYS_EXIT
        int     0x80


trick:  DB      "trick/treat$"

BITS 16
        jmp     short treat

This uses the fact that the ELF header starts with 7F 45, which, interpreted as x86 code, is a jump.

The relevant parts for the DOS .COM:

-u100 l2
07D2:0100 7F45          JG      0147
-u147 l2
07D2:0147 EBD9          JMP     0122
-u122 l8
07D2:0122 B409          MOV     AH,09
07D2:0124 BA4101        MOV     DX,0141
07D2:0127 CD21          INT     21
07D2:0129 C3            RET
-d141 l6
07D2:0140     74 72 65 61 74 24   -                           treat$

ninjalj

Posted 2016-10-25T23:57:54.160

Reputation: 3 018

4Bravo, sir. Bravo. – Draconis – 2016-10-26T22:37:23.590

9My heart skipped a beat. – John Keates – 2016-10-27T13:59:21.043

http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html is a good read for anyone interested in the header overlap trick here. – Sparr – 2016-10-31T16:26:48.867

4This is one of the finest answers i've ever seen on this site. Codegolf a little too often turns into esoteric languages purpose-built for golfing, rather than clever answers. This is beautiful. – Knetic – 2016-11-01T20:46:10.440

This is great stuff. – Gooseman – 2017-01-18T12:08:45.073

104

evil / ZOMBIE, 109 bytes

Another spooky answer !

xf is a vampire summon task f say "trick" stumble say "jzuueeueeawuuwzaeeaeeaeawuuuuwzuueeueeaw" animate bind

The ZOMBIE code defines a vampire named xf whose only task f is activated at instanciation and will output trick once before being deactivated by stumble. The other say call is dead code (how appropriate !) for ZOMBIE, but contains most of the evil code.

For evil, the xf name is a call to jump to the next j, which precedes the zuueeueeawuuwzaeeaeeaeawuuuuwzuueeueeaw zombie moan that crafts and output treat. The code following is either executed (lowercase letters) or ignored but since there's no w no output should be produced.

Aaron

Posted 2016-10-25T23:57:54.160

Reputation: 3 689

1@KevinCruijssen thanks, I enjoyed this occasion to get into some less-known esoteric languages :) – Aaron – 2016-10-26T13:40:03.610

Well, from the four you've used I have seen Agony a few times before, and I vaguely remember to have seen ZOMBIE once. Never heard of HashHell or evil before, though. :) – Kevin Cruijssen – 2016-10-26T13:43:28.973

the Halloween theming of this is impressive! I'd never even heard of those two languages – ejfrancis – 2016-10-27T21:36:48.943

95

Python / Perl, 28 bytes

print([]and"trick"or"treat")

Explanation

Since [] is an ArrayRef in Perl, it's truthy, but it's an empty array in Python, therefore falsy.

Dom Hastings

Posted 2016-10-25T23:57:54.160

Reputation: 16 415

7Similarly, print({}and"trick"or"treat") in Python / Lua. – user200783 – 2016-10-27T04:01:22.623

1@user200783 That would have the same effect in Perl as well, since {} is a HashRef! – Dom Hastings – 2016-10-27T07:05:11.900

2Is also almost identical for Python / Ruby, but requires an extra whitespace: print ([]and"trick"or"treat") – Value Ink – 2016-10-28T05:21:44.920

2Love it! This is a great commentary on what implicit conversion-to-bool does to readability. – Don Hatch – 2016-11-03T22:21:44.363

This could be a polyglot in Lua, Perl, and Python if it were print({}and"trick"or"treat")! – ckjbgames – 2017-04-23T23:54:32.890

48

PHP / JavaScript, 32 30 bytes

Displays trick in PHP and treat in JS.

NaN?die(trick):alert('treat');

The unknown NaN constant is implicitly converted to a string by PHP, making it truthy. It's falsy in JS.

Alternative method, 38 bytes

(1?0:1?0:1)?die(trick):alert('treat');

The ternary operator is right-associative in JS:

                1 ? 0 : 1 ? 0 : 1
 is parsed as:  1 ? 0 : (1 ? 0 : 1)
 which equals:  0

And left-associative in PHP:

                1 ? 0 : 1 ? 0 : 1
 is parsed as:  (1 ? 0 : 1) ? 0 : 1
 which equals:  1

Arnauld

Posted 2016-10-25T23:57:54.160

Reputation: 111 334

1You're right, my bad – Gareth Parker – 2016-10-27T14:32:52.360

alert() is JavaScript in HTML, though, not JavaScript from the console. – peter ferrie – 2016-10-29T19:03:07.883

1Alternative method: '\0'=="\0"?die(trick):alert('treat');`. – Ismael Miguel – 2016-10-30T05:00:57.180

3Debugging chained ternary operators in PHP must be so much fun. – Robert Fraser – 2016-10-30T09:08:23.000

3@Robert Debugging anything in PHP is so much fun. – sampathsris – 2016-11-03T07:00:42.580

39

HTML / HTML+JavaScript, 53 bytes

treat<script>document.body.innerHTML='trick'</script>

treat is the document´s text content in HTML.
If JS is enabled, it will replace the HTML content with trick.

Titus

Posted 2016-10-25T23:57:54.160

Reputation: 13 814

3Interesting solution. I like it – BrainStone – 2016-10-26T13:19:54.543

1You should use document.write() instead. -8 bytes – darrylyeo – 2016-10-27T14:18:07.567

@darrylyeo document.write would not replace the HTML output but append to it. – Titus – 2016-10-27T14:29:08.087

1Tested in Chrome. Fully works. Turning javascript on and off changes the content on refresh. – Tatarize – 2016-10-30T17:18:15.653

@Tatarize: Tested in Firefox 49, Opera 41, Safari 5.0, Chrome 54, Edge 38 on Windows, Firefox 5.3 and Safari 5.0 on iOS, Firefox 49 and Dolphin 11.5 on Android. Only Firefox on Windows replaces; all others append. – Titus – 2016-11-18T12:22:24.990

33

C / Java 7, 165 155 128 123 122 120 103 bytes

//\
class a{public static void main(String[] s){System.out.print("treat"/*
main(){{puts("trick"/**/);}}

//\ makes the next line also a comment in C but is a regular one line comment in Java, so you can make C ignore code meant for Java and by adding /* in the second line you can make a comment for Java that is parsed as code by C.

Edit: I improved it a little bit by reorganizing the lines and comments.

Edit2: I did some more reorganizing and shortened it even more.

Edit3: I added corrections suggested by BrainStone to remove 5 bytes, thanks :)

Edit4: One newline turned out to be unnecessary so I removed it.

Edit5: I changed printf to puts.

Edit6: I added a correction suggested by Ray Hamel.

I_LIKE_BREAD7

Posted 2016-10-25T23:57:54.160

Reputation: 431

1You can safe 1 byte by changing C to C++ and replacing #include<stdio.h> with #include<cstdio>. Not much but a byte is a byte. And additionally removing int infront of main will safe 4 bytes. int is implied by C and C++ – BrainStone – 2016-10-26T20:00:24.437

Thanks, I modified the code according to your suggestions :) – I_LIKE_BREAD7 – 2016-10-27T02:15:47.557

1

Nice! I had a hard time coming up with something for Java, and ended up with Java 7 + Whitespace myself. Btw, you can golf one more byte by removing the space at String[]s.

– Kevin Cruijssen – 2016-11-04T13:31:32.777

29

Jolf + Chaîne, 12 bytes

Because Chaîne cannot accept a file to upload with an encoding, I assume UTF-8. (If I could assume ISO-8859-7, this would be 11 bytes, but that would be unfair.)

trick«treat

In Chaîne, « begins a comment, and the rest is printed verbatim. In Jolf, « begins a string. Thankfully, trick does nothing harmful (10; range(input, parseInt(input)) basically), and treat is printed.

Try Jolf here!

Try Chaîne here!

They both work on my browser (firefox, latest version), but the same cannot be said for other browsers.

Conor O'Brien

Posted 2016-10-25T23:57:54.160

Reputation: 36 228

2I suppose being the inventory of many obscure languages has it's benefits... – Conor O'Brien – 2016-10-26T01:24:15.197

1Nice to see that we are getting close to soloutions pretty much only consiting out of the words themself. I wonder if anyone can reuse the tr. – BrainStone – 2016-10-26T01:25:12.833

1@BrainStone I personally doubt that tr could be reused in any golf--it's a small piece of information that would take at least an operator to encode in golfing languages, then a language specific conditional. It would probably even out to either the same length, or longer. However, that's just my conjecture ;) – Conor O'Brien – 2016-10-26T01:26:47.757

Let's find out. But I have to agree. A byte count of 10 or less would be insane! – BrainStone – 2016-10-26T01:31:10.460

@BrainStone, 8 bytes: http://codegolf.stackexchange.com/a/97580/5011

– SeanC – 2016-11-03T18:09:41.010

@SeanC I'm sure he's aware :P – Conor O'Brien – 2016-11-03T18:38:34.747

@SeanC I'm very well aware of this and was seriously blown away by it! – BrainStone – 2016-11-03T18:52:20.753

27

#hell / Agony, 43 bytes

So much ><> everywhere, what is this, an April Fools challenge? Here's an answer with appropriately themed languages.

--<.<.<.<.<.$
io.write("trick")--+<~}~@+{+<

#hell is a subset of LUA which fortunately accepts io.write output calls. We use LUA's -- comments so that it only executes this fragment.

Agony is a Brainfuck derivative, which has the particularity to have its code and working memory on the same tape. The first line only prints 5 characters (10 cells) from the end of the code segment, where I encoded treat as Agony commands. LUA's comment opening -- modifies the value of a cell which isn't used.

Aaron

Posted 2016-10-25T23:57:54.160

Reputation: 3 689

I have to say your Halloween themed ones are the best imho. Very creative! – BrainStone – 2016-10-26T20:10:03.393

@BrainStone Thanks, I had fun making them ! – Aaron – 2016-10-26T21:06:59.243

27

Cubix / Hexagony, 31 bytes

t;./e;_a]"kcirt">o?@;=v=./r;\;/

Trick it out! Treat it online!

Halloween themed? Note the horrifying facts about these languages and the code:

  1. If and even if you do nothing (just put no-ops), you can never get out of the loop that is determined to be running forever...
  2. And being stuck in the middle of a 3D and a 2D programming language (Oh agony...)
  3. Inside the dimensions, you'll gradually lost where you are... where you were...
  4. And there is a =v= smiling at you which acts at no-ops in the code

Let's dig into the mystery of the hidden 31-bytes communication protocol of dimensions and terror...

trick

When the code folds or unfolds itself... That is cubified, the layout looks like this:

      t ; .
      / e ;
      _ a ]
" k c i r t " > o ? @ ;
= v = . / r ; \ ; / . .
. . . . . . . . . . . .
      . . .
      . . .
      . . .

And the main part is this part in the middle:

" k c i r t " > o ? @ .
. . . . . . . \ ; / . .

It pushes k,c,i,r,t onto the stack and o outputs and ; pops within a loop bounded by reflectors and ? which guides you depending on the value on the top of the stack...

treat

All of a sudden, the code transforms from a cube to a Hexagon. (Imagine that)

   t ; . /
  e ; _ a ] 
 " k c i r t 
" > o ? @ ; = 
 v = . / r ;
  \ ; / . .
   . . . .

And the main part is this part:

   t ; . /
  e ; _ a ] 
 . . . . . . 
. . . . @ ; = 
 . . . / r ;
  . . . . .
   . . . .

It runs t; which prints t and hits the mirror and turns its direction to NW starting from the SE corner and hits another mirror. This runs r; and wraps to e;_a and the ] brings it to the Instruction Pointer 1 which starts at corner NE pointing SE and hits / which reflects horizontally to ; then t.

Then it wraps to =, ;, and @ ends the mess.

So... What is _ doing there?

Why is it inside the t e a (the first 3 letters in the code)?

Here comes the end of the story -

it does nothing.

Does it sound like the end of a horror story?

Sunny Pun

Posted 2016-10-25T23:57:54.160

Reputation: 821

Nice, very nice! It's difficult to create a polyglot out of two 2D languages. I like the horror story that goes along with it ;) – ETHproductions – 2016-10-29T01:58:06.943

Not sure if this or ELF/.COM answer is more impressive. Good job! – val says Reinstate Monica – 2019-07-05T14:53:51.253

24

SQL / Javascript, 54 bytes

select('trick')
--a;function select(){alert("treat")}

Same approach as with my QB/JS answer: First line has the SQL statement, the second line has a 'comment' for SQL and a NOP for JS. Then, we define SQL's select statement as a valid JS function.

steenbergh

Posted 2016-10-25T23:57:54.160

Reputation: 7 772

3That is a very smart way of combining these two languages. Have a +1! – ETHproductions – 2016-10-26T17:35:25.547

22

/Brainf..k/, 143 + 3 = 146 bytes

This answer requires the -A flag to output in ASCII for Brain-Flak and luckily Brainfuck doesn't care about that flag so it doesn't affect the output in Brainfuck.

(((((()(()()()){})({}){}){}){})+++++++[<+++<(((()()()())((((({}){}){}){}){}()))[][][][]())>>-])<[<++++>-]<.--.---------.------.>++[<++++>-]<.>>

Try it Online!

Try it Online!

How this works

The only overlap between the syntax of Brain-Flak and Brainfuck are the characters <>[]. For brain-flak this mostly means the program has to ensure an even number of stack switches <>. And for Brainfuck this means we need to avoid infinite loops caused by use of the [] monad.

The Brain-Flak code is as follows:

(((((()(()()()){})({}){}){}){})[<<(((()()()())((((({}){}){}){}){}()))[][][][]())>>])<[<>]<>[<>]<>>

Aside from the [<<...>>] bit in the middle and the <[<>]<>[<>]<>> at the end this code is pretty par for the course as far as Brain-Flak programs go. The negative around the zero ([<...>]) is there to create a loop for Brainfuck. The inner <...> is used to move the Brainfuck to an empty cell before it encounters the [][][][] which would loop infinitely otherwise.

The Brainfuck code is as follows:

+++++++[<+++<[][][][]>>-]<[<++++>-]<.--.---------.------.>++[<++++>-]<.>>

Aside from the aforementioned bits this is also a pretty standard program so I will spare you the details.

Post Rock Garf Hunter

Posted 2016-10-25T23:57:54.160

Reputation: 55 382

I like this one :D – Conor O'Brien – 2016-10-26T02:35:59.883

9There are a LOT more than two languages that match the regex /brainf..k/, so you should use the same header format as everyone else. – mbomb007 – 2016-10-26T13:52:11.567

13

@mbomb007 the only other language I could find that fits this regex is brainfork. Conveniently when run in brainfork this prints "TRICK" so I will leave the regex for the time being.

– Post Rock Garf Hunter – 2016-10-26T17:37:14.790

For brain-flak this mostly means the program has to ensure an even number of stack switches Are you sure about that? It shouldn't matter since <> is a NOP in brainfuck – James – 2016-10-26T21:16:30.690

@DJMcMayhem it has to end on the same stack we put everything otherwise it won't print anything. – Post Rock Garf Hunter – 2016-10-26T21:17:35.537

21

><> / Fishing, 38 bytes

_"kcirt"ooooo;
[+vCCCCCCCC
   `treat`N

For the sake of making a ><> / Fishing polyglot.

It's my first piece of Fishing code after having played for a long time with ><>.
My first impression : as in nature, the fisherman has less physical capabilities than its pray but makes up for it with its tool !

Here the code is extremely simple : ><> will only execute the first line, where _ is a vertical mirror and has no effect since the fish starts swimming horizontally. It just pushes trick on the stack then print it before stopping.
For Fishing, the _ instructs to go down. The fisherman will follow the deck that is the second line while catching the characters of the third line. These will push treat on the tape then print it, stopping as it reaches the end of the deck.

If erroring out is allowed, you could go down to 35 bytes with the following code which will throw an error when run as ><> once the trick is printed off the stack :

_"kcirt">o<
[+vCCCCCCCC
   `treat`N

You should also check my themed languages answers, #hell / Agony and evil / ZOMBIE !

Aaron

Posted 2016-10-25T23:57:54.160

Reputation: 3 689

Aw, I wanted to make a fish/fishing polyglot :) You beat me to it. Nice one! – Emigna – 2016-10-26T09:27:25.580

+1 for "as in nature, the fisherman has less physical capabilities than its pray but makes up for it with its tool !" – Kevin Cruijssen – 2016-10-26T09:27:57.583

20

05AB1E/Actually, 10 bytes

"trick"’®Â

Explanation

05AB1E

"trick"     # push the string "trick"
       ’®Â  # push the string "treat"
            # implicitly print top of stack (treat)

Try it online

Actually

"trick"     # push the string "trick"
       ’®Â  # not recognized commands (ignored)
            # implicit print (trick)

Try it online

Emigna

Posted 2016-10-25T23:57:54.160

Reputation: 50 798

You know, I can clearly read the trick, but how is ’®Â treat?.. – Kevin Cruijssen – 2016-10-26T08:52:15.740

1Now people have known this feature. Next time we'll get questions such as "hQq3k or bvM;p polyglot"... – jimmy23013 – 2016-10-26T08:55:52.263

3@KevinCruijssen: ’®Â is translated as "take the word with index 3757 from the dictionary", which is "treat". – Emigna – 2016-10-26T09:06:53.157

@Emigna Ok... So all ~1.1M English words are accessible in 05AB1E? – Kevin Cruijssen – 2016-10-26T09:11:46.083

1

@KevinCruijssen: No, there are 10k in total (each representable as 2 characters). You can find the whole list here.

– Emigna – 2016-10-26T09:22:15.313

@Emigna Ah ok. I learn something new every day. :) I guess it's always loaded into memory, or is there some sort of automatic import/using system in 05AB1E, so it only adds the dictionary to the memory if it needs it? Not that 76.6kb for a dictionary list is anything at all to load into memory; I'm just curious how it works. – Kevin Cruijssen – 2016-10-26T09:26:18.133

@KevinCruijssen: It is loaded with the interpreter so it's always in memory, but as you say it's so small it doesn't matter. – Emigna – 2016-10-26T09:32:01.843

This doesn't work. Either you have to use UTF-8 as the encoding, or you have to use the corresponding characters for CP437 from Windows-1252 (which gives "trick"Æ«┬).

– Mego – 2016-10-27T04:05:52.770

16

Haskell / Standard ML, 56 bytes

fun putStr x=print"treat";val main=();main=putStr"trick"

Haskell view

The semicolons allow multiple declarations in one line and act like linebreaks, so we get

fun putStr x=print"treat"
val main=()
main=putStr"trick"

A Haskell program is executed by calling the main function, so in the last row putStr"trick" is executed which just prints trick.
The first two rows are interpreted as function declarations following the pattern <functionName> <argumentName1> ... <argumentNameN> = <functionBody>. So in the first row a function named fun is declared which takes two arguments named putStr and x and the function body print"treat". This is a valid Haskell function with type fun :: t -> t1 -> IO (), meaning it takes an argument of an arbitrary type t and a second one of some type t1 an then returns an IO-action. The types t and t1 don't matter as the arguments aren't used in the function body. The IO-action type results from print"treat", which prints "treat" to StdOut (notice the ", that's why putStr instead of print is used in main). However as it's only a function declaration, nothing is actually printed as fun is not called in main.
The same happens in the second line val main=();, a function val is declared which takes an arbitrary argument named main and returns unit, the empty tuple (). It's type is val :: t -> () (Both the value and the type of unit are denoted with ()).

Try it on Ideone.


Standard ML view

Standard ML is a primarily functional language with a syntax related to, but not the same as Haskell. In particular, function declarations are prefixed with the keyword fun if they take any arguments, and the keyword val if they don't. Also it's possible to have an expression at top level (meaning not inside any declaration) which is executed when the program is run. (In Haskell writing 1+2 outside a declaration throws a naked expression at top level-error). Finally the symbol for testing equality is = instead of == in Haskell. (There are many more differences, but those are the only ones that matter for this program.)
So SML sees two declarations

fun putStr x=print"treat";
val main=();

followed by an expression

main=putStr"trick"

which is then evaluated. To determine whether main equals putStr"trick", both sides have to be evaluated and both must have the same type, as SML (as well as Haskell) is statically typed. Let us first have a look at the right side: putStr is not a library function in SML, but we declared a function named putStr in the line fun putStr x=print"treat"; - it takes an argument x (this is the string "trick" in our case) and immediately forgets it again, as it does not occur in the function body. Then the body print"treat" is executed which prints treat (without enclosing ", SML's print is different from Haskell's print).
print has the type string -> unit, so putStr has the type a -> unit and therefore putStr"trick" has just type unit. In order to be well-typed, main must have type unit too. The value for unit is in SML the same as in Haskell (), so we declare val main=(); and everything is well-typed.

Try it on codingground.
Note: The output in the console is

val putStr = fn : 'a -> unit                                   
val main = () : unit                                                    
treatval it = true : bool

because in SML\NJ the value and type of every statement is displayed after each declaration. So first the types of putStr and main are shown, then the expressions gets evaluated causing treat to be printed, then the value of the expression (true as both sides of = are ()) is bound to the implicit result variable it which is then also displayed.

Laikoni

Posted 2016-10-25T23:57:54.160

Reputation: 23 676

1I always thought fun ... ... = was syntactic sugar for val rec ... = fn ... =>. But then again it's been decades since I used ML. – Neil – 2016-10-27T12:31:20.143

@Neil You're right, fun is syntactic sugar for anonymous function bound with val (rec is only needed if the function is recursive) and therefore the formulation "must be prefixed" is badly chosen, I'll edit the answer. In general using fun is best-practice, especially in code golf as it's much shorter. – Laikoni – 2016-10-27T13:39:33.630

15

QBasic / JavaScript, 51 44 bytes

'';PRINT=a=>{alert("Treat")}
PRINT("Trick")

In QBasic, it prints the second line and doesn't execute the first line because it's believed to be a comment (thank you '). In JS, it calls the function PRINT, which is defined on the first line, right after the JS NOP '';.

steenbergh

Posted 2016-10-25T23:57:54.160

Reputation: 7 772

1A very clever approach! – BrainStone – 2016-10-26T08:28:18.230

15

Ruby / C, 64 62 51 48 bytes

#define tap main()
tap{puts(0?"trick":"treat");}

What Ruby sees:

tap{puts(0?"trick":"treat");}

The tap method takes a block and executes it once. It's a short identifier that we can create a #define macro for in C. It also allows us to put a braces-enclosed block in the shared code, even though Ruby doesn't allow {}s in most contexts.

The only falsy values in Ruby are false and nil. In particular, 0 is truthy. Thus, Ruby will print "trick."

What C sees (after the pre-processor):

main(){puts(0?"trick":"treat");}

0 is falsy in C, so C will print "treat."

2 bytes saved thanks to daniero.

m-chrzan

Posted 2016-10-25T23:57:54.160

Reputation: 1 390

1Nice. You can use puts instead of printf to save two bytes – daniero – 2016-10-26T17:45:20.230

Thanks! I'm so used to just always using printf in C, I've forgotten that it also has a puts function. – m-chrzan – 2016-10-26T19:47:01.407

Two ideas: Can't you use something shorter for tap? And why didn't you get rid of the spaces? p ? "trick":"treat" => p?"trick":"treat" – BrainStone – 2016-10-26T19:49:32.100

tap actually serves two purposes. It's a short identifier for #define to latch onto, but it also allows me to put the braces directly in the Ruby code. {} blocks in Ruby don't work like they do in C and similar languages, but tap does take a block, and executes it once. – m-chrzan – 2016-10-26T19:53:49.737

Method names in Ruby can end with a question mark, so a space is needed after p. ?<character> is a character literal, so a space is needed after the ?. – m-chrzan – 2016-10-26T19:57:29.743

@m-chrzan Ok. I'm not familiar with Ruby. But still a nice solution. – BrainStone – 2016-10-27T01:24:47.007

14

MATL / CJam, 17 bytes

'TRICK'%];"TREAT"

In MATL this outputs TRICK. In CJam it outputs TREAT.

Explanation

MATL

'TRICK'         Push this string
%];"TREAT"      Comment: ignored
                Implicit display

CJam

'T              Push character 'T'
R               Push variable R, predefined to empty string
I               Push variable I, predefined to 18
C               Push variable C, predefined to 12
K               Push variable K, predefined to 20
'%              Push character '%'
]               Concatenate stack into an array
;               Discard
"TREAT"         Push this string
                Implicit display

Luis Mendo

Posted 2016-10-25T23:57:54.160

Reputation: 87 464

You're missing 3 characters there! (EAT) – Destructible Lemon – 2016-10-26T00:18:29.130

@DestructibleWatermelon Thanks! Edited – Luis Mendo – 2016-10-26T00:21:09.040

Now you are missing three in the MATL explanation! – Destructible Lemon – 2016-10-27T22:09:59.403

@DestructibleWatermelon Aww. Thanks again :-D – Luis Mendo – 2016-10-27T22:52:53.077

14

ShapeScript / Foo, 13 bytes

'trick'"treat

Try it online! trick | treat

How it works

ShapeScript is parsed character by character. When EOF is hit without encountering a closing quote, nothing is ever pushed on the stack. 'trick' does push the string inside the quotes, which is printed to STDOUT implicitly.

Foo doesn't have any commands assigned to the characters is 'trick', so that part is silently ignored. It does, however, print anything between double quotes immediately to STDOUT, even if the closing quote is missing.

Dennis

Posted 2016-10-25T23:57:54.160

Reputation: 196 637

14

Ruby / Perl, 21 bytes

print"trick"%1||treat

Perl

Calculates "trick" % 1 which is 0 % 1 so the || sends treat to print instead, since Perl accepts barewords.

Ruby

Formats the string "trick" with the argument 1, which results in "trick" which is truthy, so the || isn't processed.

Dom Hastings

Posted 2016-10-25T23:57:54.160

Reputation: 16 415

13

Objective-C / C, 50 bytes

puts(){printf("trick");}main(){printf("treat\n");}

Objective-C got candy and prints treat, but C didn't and prints trick.

How it works

I don't know a lot about Objective-C, but it does what we'd reasonably expect in this situation. The re-definition of puts doesn't affect the output since we never call the function, and main prints treat and a linefeed to STDOUT.

You might expect C to do the same, but at least gcc 4.8, gcc 5.3, and clang 3.7 don't.

Since we do not need the real printf (which takes a format string and additional arguments) and the string to be printed ends with a linefeed, we can use puts instead. puts is slightly faster than printf (which has to analyze its arguments before printing), so unless we redefine the function printf as well, the compiler optimizes and replaces the call to printf with a call to puts. Little does the compiler know that calling puts with argument "treat" will print trick instead!

Not including stdio.h is crucial here, since defining puts would require using the same type it has in the header file (puts(const char*)).

Finally, it is noteworthy that the call to printf in puts passes a string without a trailing linefeed. Otherwise, the compiler would "optimize" that call as well, resulting in a segmentation fault.

Dennis

Posted 2016-10-25T23:57:54.160

Reputation: 196 637

12

Jelly / pl, 12 bytes

0000000: 74 72 65 61 74 0a 7f fe 00 ba 49 fb                 treat.....I.

This is the program displayed using Jelly's code page.

treatµ
“¡ṾI»

Try it online!

This is the program displayed using code page 437.

treat
⌂■␀║I√

Try it online!

Both programs have been tested locally with the same 12 byte file, so this is a proper polyglot.

How it works

In Jelly, every line defines a link (function); the last line defines the main link, which is executed automatically when the program is run. Unless the code before the last 7f byte (the linefeed in Jelly's code page) contain a parser error (which would abort execution immediately), they are simply ignored. The last line, “¡ṾI» simply indexes into Jelly's dictionary to fetch the word trick, which is printed implicitly at the end of the program.

I don't know much about pl, but it appears that the interpreter only fetches one line of code and ignores everything that comes after it. As in Perl, barewords are treated as strings, so treat prints exactly that.

Dennis

Posted 2016-10-25T23:57:54.160

Reputation: 196 637

10

Brain-Flak / Brain-Flueue, 265 253 219 165 139 115 113 101 bytes

Includes +1 for -A

Thanks to Wheat Wizard for going back and forth, golfing a few bytes off each others code, with me.

((((()()()))([]((({}{}))({}([((({}()())))]([](({}{}){}){}{})))[]))[])[()()])({}()()){}({})({}[][]){}

Brain-Flak: Try it online!
Brain-Flueue: Try it online!

Explanation:
The first section lists the values that Brain-Flak sees.
When it switches to Brain-Flueue, I start listing the values as Brain-Flueue sees them.

# Brain-Flak
(
 (((()()()))             # Push 3 twice
  ([]                    # Use the height to evaluate to 2
   (
    (({}{}))             # Use both 3s to push 6 twice
    ({}                  # Use one of those 6s to evaluate to 6
     ([((({}()())))]     # Use the other 6 to push 8 three times and evaluate to -8
      ([](({}{}){}){}{}) # Use all three 8s to push 75
     )                   # The -8 makes this push 67
    )                    # The 6 makes this push 73
   [])                   # Use the height and the 6 to push 82
  )                      # Use the 2 to push 84

# Brain-flueue
 [])     # Use the height and 3 to push 84
[()()])  # Push 82
({}()()) # 67 is at the front of the queue, so use that to push 69
{}       # Pop one from the queue
({})     # 65 is next on the queue so move to the end
({}[][]) # 74 is next, so use that and the height to push 84
{}       # Pop that last value from TRICK

Riley

Posted 2016-10-25T23:57:54.160

Reputation: 11 345

A little competition – Post Rock Garf Hunter – 2017-04-19T14:23:43.930

10

Batch/sh, 30 bytes

:;echo Treat;exit
@echo Trick

Explanation. Batch sees the first line as a label, which it ignores, and executes the second line, which prints Trick. The @ suppresses Batch's default echoing of the command to stdout. (Labels are never echoed.) Meanwhile sh sees the following:

:
echo Treat
exit
@echo Trick

The first line does nothing (it's an alias of true), the second line prints Treat, and the third line exits the script, so the @echo Trick is never reached.

Neil

Posted 2016-10-25T23:57:54.160

Reputation: 95 035

10

sed / Hexagony 32 bytes

/$/ctrick
#$@$a</;r;e;/t;....\t;

sed

Try it Online!

The first line prints trick if there is an empty string at the end of input. (sed doesn't do anything if there isn't input, but a blank line on stdin is allowed in this case)

Example run:

$ echo | sed -f TrickOrTreat.sed
trick

Hexagony

Try it Online!

The first / redirects the instruction pointer up and the the left, so it wraps the the bottom left, skipping the text used for sed. It reuses the r from the sed code and runs a few others to no effect. The expanded hex looks like this:

   / $ / c 
  t r i c k
 # $ @ $ a <
/ ; r ; e ; /
 t ; . . . . 
  \ t ; . .
   . . . .

Output:

treat

Riley

Posted 2016-10-25T23:57:54.160

Reputation: 11 345

I've seen Hexagony posts that have pictures of the execution path, is there an easy to generate those? – Riley – 2016-10-26T19:17:19.337

Here it is https://github.com/Timwi/HexagonyColorer

– 0 ' – 2016-10-27T01:09:44.870

1Your Hexagony code prints a leading null byte. Not sure if that counts as whitespace for the purposes of this challenge. – Martin Ender – 2016-10-27T12:05:09.980

@MartinEnder Sounds like it's allowed. Thanks for pointing that out, I always miss those for some reason... – Riley – 2016-10-27T12:14:58.713

I managed to fix that while also saving a few bytes (at the cost of printing an upper case A, although you could make that less ugly by changing all letters to upper case): http://hexagony.tryitonline.net/#code=LyQvY3RyaWNrCiM7QUAkPC87cjtlOy90&input=

– Martin Ender – 2016-10-27T13:21:05.033

@MartinEnder This is my first time using Hexagony, so I didn't really look at the other pointers at all. This new one prints all lowercase without a null byte, but is a little longer. – Riley – 2016-10-27T13:40:33.603

@1000000000 How do you run that tool? – Riley – 2016-10-27T13:43:01.067

10

C# / Java

This probably doesn't qualify as it doesn't run on its own, but the challenge has reminded me of a quirk in how C# and Java handle string comparison differently that you can have some fun with for code obfuscation.

The following function is valid in C# and Java, but will return a different value...

public static String TrickOrTreat(){
    String m = "Oct";
    String d = "31";
    return m + d == "Oct31" ? "Trick" : "Treat";
}

Brainfloat

Posted 2016-10-25T23:57:54.160

Reputation: 201

Interesting quirk indeed. – BrainStone – 2016-10-27T14:04:44.640

9

Python / Pyth, 24 22 bytes

Thanks to @Loovjo and @Pietu1998 for some help

#"treat"
print"trick";

In Pyth, this outputs treat. In Python, this outputs trick.

How it works

Python

#"treat"       Comment
print"trick";  Print the string literal "trick"

Pyth

#"treat"     
#              Loop until error statement
 "treat"       Implicitly print the string literal "treat"
print"trick";  Throws an error since n has no right operand, breaking out of the loop
               The last ";" is a valid EOF

TheBikingViking

Posted 2016-10-25T23:57:54.160

Reputation: 3 674

2Couldn't you replace the .q with something that gives an error (e.g. K)? Edit: you can remove the .q all together as Pyth will try to run the second line and fail – Loovjo – 2016-10-26T05:22:09.913

1To add to @Loovjo's comment, n fails as it has no second operand. – PurkkaKoodari – 2016-10-26T06:22:46.140

9

PowerShell / Foo, 14 bytes

'trick'#"treat

The 'trick' in PowerShell creates a string and leaves it on the pipeline. The # begins a comment, so the program completes and the implicit Write-Output prints trick.

In Foo, (Try it Online!), the 'trick' is ignored, the # causes the program to sleep for 0 seconds (since there's nothing at the array's pointer), then "treat starts a string. Since EOF is reached, there's an implicit " to close the string, and that's printed to stdout.

AdmBorkBork

Posted 2016-10-25T23:57:54.160

Reputation: 41 581

Also works in J / Foo. – Conor O'Brien – 2016-10-26T03:50:19.650

@ConorO'Brien Is the explanation the same? I've never used J and I'm not familiar with it. – AdmBorkBork – 2016-10-26T04:03:35.010

No, this doesn't work in J. # is the copy function, and it only takes non-negative complex left arguments, not strings. The comment symbol is NB. – Adám – 2016-10-26T09:03:25.580

@Adám right you are. Forgot the # – Conor O'Brien – 2016-10-26T11:02:24.757

9

PHP/Perl, 28 bytes

print defined&x?trick:treat;

defined&x
gives something truthy in PHP (no idea why, but it does).
In Perl it checks if function x is defined - which is not.
--> trick in PHP, treat in Perl.

Titus

Posted 2016-10-25T23:57:54.160

Reputation: 13 814

@jmathews Have you tried putting a backspace control character into your windows version? What about CLS?

– Titus – 2016-10-26T12:13:57.853

``` is the truthy value of defined&x or d&x ask me not which d you get – Jörg Hülsermann – 2016-10-27T16:37:39.937

9

/// / Javascript, 32 26 bytes

/*//trick/*/alert("treat")

Try it online! Slashes | Javascript

-6 bytes thanks to BrainStone

Explanation:

  • ///

    /*//                        Replace * with nothing
       trick                    Print "trick"
            /*/alert("treat")   This is the start of a replacement,
                                but the third slash is missing,
                                so it doesn't do anything.
    
  • Javascript

    /*                          Start of multiline comment
      //trick/                  Comment
              */                End of multiline comment
                alert("treat")  Print "treat"
    

acrolith

Posted 2016-10-25T23:57:54.160

Reputation: 3 728

You can replace console.log with alert to save some bytes. – BrainStone – 2016-10-26T17:10:25.127

Wow, that second - incomplete - / statement is very nice! I tried the same, but came to /*\/alert('treat')/trick/*/alert('treat') because I was unaware of this behaviour and tried to do a complete replace. – steenbergh – 2016-10-27T08:54:27.727

8

Labyrinth/><>, 32 30 bytes

Saved 2 bytes thanks to Martin Ender

v84.82."73.67.75.@
\"TAERT"
>o

Explanation

Labyrinth (TRICK)

The numbers represent ascii values of the letters in "TRICK"
. prints the ascii codes as bytes and @ exists the labyrinth.

Try it online

><> (TREAT)

Moves down and right and pushes the letters of "TAERT" to the stack.
Then loops to the beginning of the line, moves down and right.
Prints everything on the stack with o.

v
\"TAERT"
>o

Try it online

Emigna

Posted 2016-10-25T23:57:54.160

Reputation: 50 798

7

Befunge-98/><>, 24 bytes

Thanks to @ninjalj for reminding me about k which saved 2 bytes.

"trick"rooooo@,k4"trea"

You can try ><> here and Befunge-98 here.

Befunge-98 pushes the characters trick, reverses direction, pushes kcirt and aert, prints the five characters on top of stack and quits.

><> pushes the characters trick, reverses the stack, prints the five characters on top of stack and errors out for no operands for @.

PurkkaKoodari

Posted 2016-10-25T23:57:54.160

Reputation: 16 699

You can skip the ; if you error out in fish. – Emigna – 2016-10-26T09:20:50.513

7

Perl / Perl 6, 41 bytes

I don't believe they count as two versions of the same language; rather, I'll consider them different languages.

my @a="ick";my $a="eat";print "tr$a[0]\n"

Explanation

This code relies on differences in sigil declension.

Perl: $a[0] means get the first element of @a, which happens to be a scalar.

Perl6: $a[0] means get the first element of $a. If we wanted the first element of @a, we could use @a[0] instead.

bb94

Posted 2016-10-25T23:57:54.160

Reputation: 1 831

I'm not a Perl expert, but can you use barewords and drop the quotes from ick and eat? Also, is my necessary? – DLosc – 2016-10-27T02:49:03.663

The quotes and my are necessary in Perl 6, but not in Perl 5. – bb94 – 2016-11-04T02:03:42.713

7

Python/Javascript (interpreters), 36 27 bytes

["Trick","Treat"][+(1/2>0)]

Explanation

1/2>0 will return False in Python, but true in JS.

Both languages use + to convert the boolean expression to an integer (+False is 0, +True is 1)

So, Python will evaluate the expression:

["Trick","Treat"][+False]

And Javascript will evaluate:

["Trick","Treat"][+true]

Python will return "Trick", Javascript will return "Treat"!

Thanks for @daHugLenny for 9 bytes saved :-)

Yotam Salmon

Posted 2016-10-25T23:57:54.160

Reputation: 201

You can replace 1e100==10**100 with 1/2>0 (if you're using Python 2) – acrolith – 2016-10-30T18:46:56.393

@daHugLenny Cool, thanks :) I'll improve the solution! – Yotam Salmon – 2016-10-30T19:12:14.493

6

FOG / Jolf, 16 14 bytes

"trick"X"treat

Jolf prints the "treat at the end (doesn't need the matched quote), X does nothing in this case (it's JS eval on the input, which there is none), and the "trick" just makes a string that isn't used.

In FOG, the "trick" pushes trick to the stack, and the X prints it. The unmatched quote on the end of "treat exits with an error.

Old Code:

a"trick""treat"X

Simple. In Jolf, a means print the string after it and disables auto-output. (not really the last part, but yes in this situation)

The other 2 commands are ignored pretty much. (X uses JS eval on the input (I think), and "treat" also gets a string ready to use in a function. No function is used though, so these don't do anything.)

In FOG, X prints the most recent item on the stack. a adds the top 2 elements on the stack (0 and 0, gives 0), and "trick""treat" pushes trick and then treat, and the X prints the top one.

Rɪᴋᴇʀ

Posted 2016-10-25T23:57:54.160

Reputation: 7 410

What is FOG? I have not heard of that language. – ETHproductions – 2016-10-26T01:02:09.207

1

@ETHproductions FOG, or Fuzzy Octo Guacamole, is his language.

– Conor O'Brien – 2016-10-26T01:12:24.980

Actually, X is eval'd input. Subtle difference. – Conor O'Brien – 2016-10-26T01:21:12.957

@ConorO'Brien eh, close enough. Will edit with links also. – Rɪᴋᴇʀ – 2016-10-26T01:25:33.250

6

Dip/05AB1E, 15 bytes

"trick"q"treat"

Prints treat in Dip and trick in 05AB1E.

Oliver Ni

Posted 2016-10-25T23:57:54.160

Reputation: 9 650

10My brain read the header as "Disposable." :P – DLosc – 2016-10-26T20:01:10.390

6

Clip and Wake, 15 bytes

15 bytes

Guess what the two languages are.

"trick":"treat"

jimmy23013

Posted 2016-10-25T23:57:54.160

Reputation: 34 042

6

Python 2, PHP - 30 bytes

Code

print["trick","treat"][""==0];

Explanation

""==0 is evaluated to true in PHP, false in Python, so Python will print the first element from list (index 0, equal to false), PHP will print the second item (index 1, equal to true).

yedpodtrzitko

Posted 2016-10-25T23:57:54.160

Reputation: 161

6

05AB1E/2sable, 13 bytes

žQ„®Â „ÐË 1@=

Try it online! (2sable), Try it online! (05ab1e)

Explanations:

05ab1e:

žQ                Push list of printable ascii characters
  „®Â             Push dictionary compressed string "treat"
      „ÐË         Push dictionary compressed string "trick"
                  STACK: *ascii*, treat, trick
          1@=     Print second item on stack (treat)

2sable:

žQ                Not a command (ignored)
  „®Â             Push dictionary compressed string "treat"
      „ÐË         Push dictionary compressed string "trick"
                  STACK: treat, trick
          1@=     Print second item on stack (trick)

Geno Racklin Asher

Posted 2016-10-25T23:57:54.160

Reputation: 466

6

Japt / GolfScript, 15 bytes

"trick""treat";

Japt implicitly prints the last string literal, "treat", the first string "trick" is basically ignored.

GolfScript pushes both strings to the stack and then the semicolon ; pops "treat" and thus only "trick" remains on the stack which is printed at the end.

theonlygusti

Posted 2016-10-25T23:57:54.160

Reputation: 1 221

Thanks for using Japt :-) trick and treat can each be represented as a 3-byte compressed string (here's how), so I wonder if that can help you save any bytes.

– ETHproductions – 2016-10-29T02:13:00.893

@ETHproductions Wow, didn't know Japt could do that. Honestly, only found out about the language in the writing of this entry xD – theonlygusti – 2016-10-29T06:23:27.730

5

Brain-Flak/Brain-Flueue, 136 124 120 108 + 1 = 109 bytes

+1 byte for the -A to cause character output

((((()()()))([]((({}{}))({}([((({}()())))]([](({}{}){}){}{})))[]))[])[()()])(({}()())<{}{}>[[]]())({}[][]){}

Try it online! Brain-Flueue

Try it online! Brain-Flak

This is a non-trivial modification of Riley's answer, which he has since golfed down even further than I have. I recommend you check out if you have not already.

Post Rock Garf Hunter

Posted 2016-10-25T23:57:54.160

Reputation: 55 382

5

VBA/Windows Batch, 21 Bytes

?"trick"'||echo.treat

For VBA, use the immediate window. ? is print, ' makes the remainder of the line a comment For Windows Batch, the || is an OR and makes the second bit run even if the first errors

Chronocidal

Posted 2016-10-25T23:57:54.160

Reputation: 51

Welcome to PPCG! Nice first post! – Rɪᴋᴇʀ – 2016-10-26T12:14:07.013

5

CJam / Stuck, 19 17 Bytes

Stuck makes a comeback!

"trick"e#"treat"p

CJam will print trick, and Stuck will print treat! Here's an explanation in both languages.

CJam:

"trick"            e# pushes the strings "trick" to the stack
       e#"treat"p  e# the e# comments everything else out, stack implicitly prints

Stuck: note that Stuck does not have comments so you can't run the below

"trick"e#"treat"    | pushes the values "trick", e^2, "treat" to the stack
                p   | prints the top stack value


Old Versions:

19 Bytes: "tr""ick""eat";e#yy

Kade

Posted 2016-10-25T23:57:54.160

Reputation: 7 463

5

TI-Basic / BF, 49 bytes

Pretty straightforward. The advantage is that it works with both your computer and your calculator :)

"-[--->+<]>-.--.---------.------.++++++++.
"TREAT

Timtech

Posted 2016-10-25T23:57:54.160

Reputation: 12 038

5

Bash / Retina, 16 bytes

echo trick||
treat

Try it online! trick | treat

How it works

Bash quite literally echoes trick or treat. Since the command echo trick successfully prints to STDOUT, the OR part isn't executed, so treat doesn't even generate a command not found error.

Retina begins with an empty space. Since there's an even amount of lines, it will perform a substituion. The regex echo trick|| matches the string echo trick, the empty string, or the empty string, and replaces the match (the empty string) with treat.

Dennis

Posted 2016-10-25T23:57:54.160

Reputation: 196 637

5

C/C++, 76 74 bytes

#include <stdio.h>
int main(){printf("tr%.3s\n",&"ickeat"[sizeof'a'-1]);}

Lots of C and C++ programmers react strongly when someone writes C/C++ as if it was one language. This contribution is here both to trigger those who are allergic to that string and to demonstrate that they (or rather: we), in fact, are right. C and C++ are two different languages.

The explanation is simple. Character constants like 'a' have different types in C and C++, so sizeof will return different sizes. This assumes a relatively normal machine where sizeof int is 4.

Art

Posted 2016-10-25T23:57:54.160

Reputation: 545

Note sizeof'a' works and saves you 2 bytes! In fact, I considered the prefix trick, and it actually costs more than it saves. – BoBTFish – 2016-10-27T09:37:05.670

@BoBTFish Old habits of being careful die hard. – Art – 2016-10-27T09:38:23.157

Didn't really go for golfing this, rather for obfuscation. puts(sizeof'a'-1?"treat":"trick") is shorter, but it's boring. – Art – 2016-10-27T09:43:32.623

5

Triple glot: ///, SQL and JavaScript, 63 bytes

/*//trick/\*/select('or')
--a;function select(){alert('treat')}

Using my SQL/Javascript answer, and @daHugLenny 's excellent ///-Javascript post, I was able to make a piece of code run across three languages:

///

/*//trick/../..   Simply prints 'trick', does no replaces, stops execution because the second /// block is incomplete

SQL

/*//trick/\*/     //trick/\ is seen as a block comment
                  That last \ was added to set apart the following */, completing the block
select('or')      SQL Select statement, yielding 'or'
--a;...           Seen by SQL as a comment, ignored

Javascript

/*//trick/\*/     //trick/\ is seen as a block comment
select('or')      Function call to the function 'select', defined below
--a;              Decrement a, effectively a NOP
function select(){alert('treat')}
                  Defines the function select(), giving us 'treat'

steenbergh

Posted 2016-10-25T23:57:54.160

Reputation: 7 772

5

gcc C/Python 3, 76 53 bytes

#define print(_)main(){puts("trick");}
print("treat")

Saved 23 bytes thanks to Dennis!

The gcc C preprocessor replaces the print macro (discarding it's argument) with a C program that prints "trick". And Python 3 ignores the first line as a comment and simply prints "treat".

Noodle9

Posted 2016-10-25T23:57:54.160

Reputation: 2 776

5

reticular + Turtlèd, 16 bytes

"trick"oll"eat";

Try reticular online! Try Turtlèd online!

reticular explanation:

"trick"oll"eat";
"trick"           push the string "trick" to the stack
       o          output it
        l         push length of stack (0)
         l        push length of stack (1)
          "eat"   push the string "eat" to the stack
               ;  terminate

Turtlèd explanation:

"trick"oll"eat";
"trick"           write "trick" to the grid, move turtle to the "k"
       o          idk, probably no-op
        ll        move turtle left two, to the "i"
          "eat"   write "eat" to the grid
               ;  something

Conor O'Brien

Posted 2016-10-25T23:57:54.160

Reputation: 36 228

5

VBA/R 16 bytes

    ?"trick";'treat'

VBA shows trick and R shows treat, can be reverse.

Explanation

In VBA/R, ";" can be used for ending.

In VBA, single quotation start the comment and anything after that is ignore.

In R, "?" go to look for documentation, single/double quotation can be used for words.

Kevin H.Y. Hau

Posted 2016-10-25T23:57:54.160

Reputation: 71

5

Befunge/Whitespace, 113 chars

Probably not going to win on shortness, but at least, I had fun ! Here is the hastebin

"taert">:#,_@                     .
 .
         .
         .
        .
   .
            .
         .
        .
   .
             .
         .
        .
   .
           .
        .
        .
    .
  .
.

I have put dots to make sure SE show it well

Try the befunge online !

Try the whitespace online !

FliiFe

Posted 2016-10-25T23:57:54.160

Reputation: 543

113 bytes unless I'm missing something. – Linus – 2016-10-31T06:13:44.707

Yep, I had put an extra linefeed when couting. Thanks – FliiFe – 2016-10-31T09:34:09.387

In case you want to add them, here are permalinks for Befunge and Whitespace.

– Dennis – 2016-11-25T00:37:16.780

@Dennis Added them. Thanks ! – FliiFe – 2016-11-26T18:08:54.183

4

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.

l=["trick","treat"]
print(l[1])

Try it online - Julia!

Try it online - Python!

Rohan D

Posted 2016-10-25T23:57:54.160

Reputation: 41

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 – Stephen – 2017-08-10T21:05:50.083

Welcome to PPCG, nice first golf! And you still haven't removed the space after , as far as I can tell. – Zacharý – 2017-08-10T21:21:48.020

Forgot about that one! Thanks! – Rohan D – 2017-08-10T21:24:28.527

4

Turtlèd, Python, 23 bytes

"Treat";print('Trick' )

Produces Treat in Turtlèd, Trick in Python

probably also produces "Treat" in foo

Explanation:

Turtlèd

"Treat"                  Write Treat
       ;                 Move down by register amount. nop as register is 0
        print            Nops and move right
             ('          if current cell is ' (it will not be)
               Trick'    Nops, move right, write a space
                      )  End if
    [implicit print grid]

Python

(I can't ideone right now)

"Treat";                   comment
        print('Trick' )    print "Trick" to output

Destructible Lemon

Posted 2016-10-25T23:57:54.160

Reputation: 5 908

4

Clojure + Common Lisp, 29 28 bytes

(print(if '()"trick"'treat))

Clojure version on ideone: https://ideone.com/3xIhpb

Common Lisp: https://ideone.com/N3qzIW

In Common Lisp nil is the same as '() and thus '() evaluates to false whereas in Clojure empty list is not nil and thus is true. I hope its being not a full program but a snippet(?) is fine for the challenge.

cliffroot

Posted 2016-10-25T23:57:54.160

Reputation: 1 080

If it runs on Ideone without any additional code required, in both languages, I'd say that qualifies as a full program for our purposes. +1 from me. – DLosc – 2016-10-27T02:51:24.403

4

LiveScript + JavaScript ES6, 29 bytes

alert(/.*/=='trick'||'treat')

In LiveScript comparing a regular expression with a string literal return an array with the matches of the expression in the string. In JavaScript it only returns true the string representation of both are the same. alert will convert it's input to string, displaying ['trick'] as just trick.

Gustavo Rodrigues

Posted 2016-10-25T23:57:54.160

Reputation: 261

'tr'+(/.*/=='ick'||'eat') is just 25 bytes, but seems it's not allowed as it isn't neither a function or a full program. – Gustavo Rodrigues – 2016-10-26T11:00:12.463

And /.*/=='trick'||'treat' is 22 ;) – ETHproductions – 2016-11-01T15:18:41.910

4

Scala / CSS, 64 bytes

/*\u002A/ print("trick")//*/
/*/**/
*:after {content:'treat';}*/

Try it: jsfiddle ideone (warning: wrong syntax highlighting)

Scala, like java, evaluates unicode escapes (\u002A, asterisk) before anything else, so scalac parses the code like

/**/                          //block comment
print("trick")                //code
//*/                          //eol-comment
/*                            //scala supports nested block comments, so this comment...
  /*
  */
  p:after {content:'treat';}
*/                            //...ends here

The CSS is parsed like this:

/*hello\u002A/ print("trick")//*/  //block comment
/*                                 //a block comment 
  /*                                 //with a slash and an asterisk
*/                                 //ending here
p:after {content:'treat';}         //code
*/                                 //invalid css syntax, jsfiddle silently ignores this

corvus_192

Posted 2016-10-25T23:57:54.160

Reputation: 1 889

Are you sure if the CSS is valid if you need the HTML? – Solomon Ucko – 2016-11-27T01:07:10.513

@SolomonUcko Most browsers imply <html></html> tags, and * matches every element, including html. – corvus_192 – 2016-11-27T16:18:35.423

Good point. I just got confused when you changed it to a p tag in the explanation – Solomon Ucko – 2016-11-27T16:42:42.340

4

////D1ffe7e45e, 59 bytes

See what I did there?

/@//TREAT
/37333120813633633333333363333336222222226//
/$/__/

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.

Timtech

Posted 2016-10-25T23:57:54.160

Reputation: 12 038

Well those comments disappeared o_O – Timtech – 2016-10-27T23:24:28.280

I don't think this works again. the /@/__/ is changed to //__/, so it doesn't halt – Destructible Lemon – 2016-10-27T23:27:21.377

(replace the first or second @ with something else) – Destructible Lemon – 2016-10-27T23:28:33.563

Yeah makes sense, this is my first time with this language ^_^ – Timtech – 2016-10-28T11:06:05.837

4

/// / FEU, 24 bytes

/ /
p/trick/
end
a/treat

Try it online! Slashes | FEU

Explanation

  • ///

    / /       Replace space with "\n...
    p/trick/  ...p". Print "trick". Replace "\n...
    end       ...end\n...
    a/treat   ...a", third slash is missing so it doesn't do anything.
    
  • FEU

    / /       Execute the next block for each strings matched by " "
    p/trick/  Prepend "trick"
    end       End block
    a/treat   Append "treat"
    

acrolith

Posted 2016-10-25T23:57:54.160

Reputation: 3 728

4

PHP, Lua 41 Bytes

PHP print trick an Lua treat

--$a;echo"trick";/*
print("treat")
--*/

Jörg Hülsermann

Posted 2016-10-25T23:57:54.160

Reputation: 13 026

You don't need the 2nd $a;. That is inside comment in both languages. – manatwork – 2016-11-01T09:00:03.547

You can join the 2nd and 3rd lines. And better check your count as currently I see there only 39 bytes. – manatwork – 2016-11-02T15:19:37.233

4

Python and Lua, 29 bytes

This solution is posted separately from but in addition to my other solution due to the use of a different set of languages and a much more competitive byte count.

The 29th byte is the newline at the end. In Python, the empty string '' is considered a falsey value, while in Lua, it's considered true. In Lua, the or is short-circuited by ''and'trick' evaluating to a true value and printing, while in Python the and short-circuits due to '' and prints the true value on the other side of the or.

print(''and'trick'or'treat')

James Murphy

Posted 2016-10-25T23:57:54.160

Reputation: 267

Do you need to count the newline at the end? – ETHproductions – 2016-11-03T21:56:17.720

I don't know. Python's interpreter occasionally throws a fit when you omit it, but only with occasional syntactic oddities. – James Murphy – 2016-11-03T21:58:45.470

4

VBScript, JScript, 41 bytes

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

The VBScript "rem" hides the JScript code.

peter ferrie

Posted 2016-10-25T23:57:54.160

Reputation: 804

4

CJam / HTML, 17 14 bytes

Edit:

  • -3 bytes off. Thanks to @ETHProductions

Code:

TREAT<"trick"

HTML:

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

CJam:

TREAT<;"trick"
TREAT<         e#random stuff / push vars
      ;        e#discard stack
       "trick" e#literal trick
               e#implictly print

Roman Gräf

Posted 2016-10-25T23:57:54.160

Reputation: 2 915

I think HTML is not considered a programming language. – FliiFe – 2016-10-31T09:45:43.317

I think you can remove the !--. – ETHproductions – 2016-11-03T21:55:36.427

@FliiFe Lets say it's PHP. Would work too. – Roman Gräf – 2016-11-06T12:43:43.400

@FliiFe you're allowed to use non-programming-languages in constant output challenges. – Pavel – 2017-04-24T01:58:38.123

4

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.

Dada

Posted 2016-10-25T23:57:54.160

Reputation: 8 279

I did not know that was possible! Good to know... Shame it's not global: perl -E'eval"#line 9\nsay __LINE__";say __LINE__' – Dom Hastings – 2016-11-02T09:16:49.647

@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.. – Dada – 2016-11-02T09:39:53.453

4

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:

a=1//2;alert=print
alert(["trick","treat"][a])

Python 3

This is how Python sees the code:

a=1//2;alert=print
alert(["trick","treat"][a])

// 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".

JavaScript

This is how JS sees the code:

a=1//2;alert=print
alert(["trick","treat"][a])

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".

ETHproductions

Posted 2016-10-25T23:57:54.160

Reputation: 47 880

4

JavaScript (ES6) / Japt, 47 33 22 bytes

1
alert`trick`;"treat"

JavaScript

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

Japt

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.

ETHproductions

Posted 2016-10-25T23:57:54.160

Reputation: 47 880

3

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.

Explaination

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.

NieDzejkob

Posted 2016-10-25T23:57:54.160

Reputation: 4 630

3

Bash / Batch, 37 32 bytes

The perfect contrast, Linux vs. Windows!

echo;echo trick;exit<0echo treat

How it works on Linux: Try it online!

echo;                               -echo nothing
     echo trick;exit;               -echo trick
                     <0echo treat   -ignored by parser (already exited)

How it works on Windows:

echo;                               -echo nothing
                    <0              -find directory (with argument of 0)                  
     echo trick;exit                -can't find directory (skips command)
                      echo treat    -echo treat

-1 byte, Thanks to CartManager XD

-4 bytes by golfing a better way to comment

Graviton

Posted 2016-10-25T23:57:54.160

Reputation: 2 295

Why do you need the comment # if you have exited? I don't know batch but I would think echo;echo trick;exit;>NUL&echo treat would work – Post Rock Garf Hunter – 2017-04-23T05:05:32.670

Or even echo;echo trick;#>NUL&echo treat. – Post Rock Garf Hunter – 2017-04-23T05:09:10.247

@CartManagerXD, that's a good idea, but for some reason the space in between exit and # has to be there. Although, you're right, you can remove the #, and then replace the space with a ;. All in all it removes one byte – Graviton – 2017-04-23T22:54:25.077

What is the purpose of the first echo? – user41805 – 2017-08-10T19:19:51.920

@Cowsquack Without it, windows will also echo trick. For some reason echoing something before the echo tick renders everything up to the <0 unparsable for windows. – Graviton – 2017-08-11T01:35:03.327

3

C/C++, 75 bytes

#include <stdio.h>
int main(){puts(sizeof'a'<sizeof(int)?"treat":"trick");}

user68468

Posted 2016-10-25T23:57:54.160

Reputation:

Welcome to PPCG! I've added in the byte count for your submission. There are a few optimizations you can make here. For starters, a lot of whitespace is unnecessary, so removing it would shorten the byte count. sizeof('a')<sizeof(int) is shorter by 1, though it causes the outputs to be swapped. Additionally, return types aren't strictly necessary for main - GCC assumes int if it's not explicitly stated. – Mego – 2017-04-24T05:01:11.790

Combining all of my suggestions, this comes out to 74 bytes.

– Mego – 2017-04-24T06:32:03.917

Also the parenthesis around the comparison are unnecessary. Which would save another 2 bytes. – BrainStone – 2017-04-24T09:19:03.353

You can remove the space between #include and <stdio.h> to save a byte – NieDzejkob – 2018-01-19T15:01:04.880

3

betseg

Posted 2016-10-25T23:57:54.160

Reputation: 8 493

3

Jelly / 05AB1E, 14 bytes

0000000: FE 22 74 52 69 63 6B 22 3F 37 29 FB ED 35                ."tRick"?7)..5

A fun one using Jelly's string compression.

Jelly: treat

“"tRick"?7)»ḣ5

Try it online!

05AB1E: trick

þ"tRick"?7)ûí5

Try it online!

How it works

In Jelly “"tRick"?7)» is a compressed string that returns 'Treatment dormy/ Orly awry'. ḣ5 takes the first five characters, printing Treat

In 05AB1E þ doesn't affect the program. "tRick" is a literal string. ? prints this string then the rest of the program (7)ûí5) doesn't have any effect either.

I used this to convert from Jelly's code page to 05AB1E's code page. This does the reverse in case anyone is interested.

Jelly code page is here.

05AB1E code page is here.

dylnan

Posted 2016-10-25T23:57:54.160

Reputation: 4 993

1First answer that actually uses the rule that arbitrary capitalization is acceptable! I like it – BrainStone – 2018-01-17T05:42:06.170

@BrainStone Thanks! I think it's also one of the few (or maybe only) answer that uses the same core code in each language to produce the words 'trick' and 'treat'. In most other answers those are separate – dylnan – 2018-01-18T22:23:29.080

That is correct – BrainStone – 2018-01-19T05:42:17.803

3

Java 8 / Whitespace, 169 145 142 141 125 bytes

The Ns are only added so the code has the correct indentations, which represent newlines for the Whitespace part of the program (see explanation below for the spaces and tabs used).

interface M{static void main(String[]a){System.out.print("TREAT");}}N
           N
         N
            N
        N
N
  N
                N
        N
  N
 N
N

Try it here : Whitespace (outputs TRICK)
Try it here : Java 8 (outputs TREAT)

Explanation:

Java:
The Java part is pretty straight-forward. It's a full program with mandatory main-method, which prints TREAT to STDOUT. All (leading and) trailing spaces, tabs and newlines are ignored.

Whitespace:
Whitespace uses spaces, tabs and new-lines as its source-code, ignoring everything else. Here is the same code with the spaces replaced with S, tabs replaced with T, and new-lines appended with N for better readability:

SSSN                          # Push 0    (K)
SSTTSSSN                      # Push -8   (C)
SSTTSSN                       # Push -2   (I)
SSSTTTN                       # Push 7    (R)
SSSTSSTN                      # Push 9    (T)
NSSN                          # Create Label LOOP
 SSSTSSTSTTN                  #  Push 75
 TSSS                         #  Add the top two values on the stack together
 TNSS                         #  Pop and output as character with this codepoint
 NSNN                         #  Jump to Label LOOP

Instead of printing directly, pushing the lowered values in reverse to the stack, and then adding a constant in a loop before printing saves 16 bytes. I've used this approach in a lot of other Whitespace programs of mine, and it can also be found in this Whitespace tip. The constant 75 is generated by this Java program, which I've created for previous challenges.

Kevin Cruijssen

Posted 2016-10-25T23:57:54.160

Reputation: 67 575

1You should be able to work the java code in. Would save some bytes – BrainStone – 2016-10-26T08:22:48.917

@BrainStone Good point, I've changed it for -24 bytes. Thanks. – Kevin Cruijssen – 2016-10-26T08:37:51.380

3

Scala / Javascript, 33 bytes

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

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

corvus_192

Posted 2016-10-25T23:57:54.160

Reputation: 1 889

3

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,@|
0000001b

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.

ninjalj

Posted 2016-10-25T23:57:54.160

Reputation: 3 018

3

Charcoal and Pip, 13 bytes

trick©"treat"

Charcoal

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

Pip

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

DLosc

Posted 2016-10-25T23:57:54.160

Reputation: 21 213

3

C/Lua, 65 bytes

#include<stdio.h>/*
print"trick"--[[*/
main(){puts("treat");}//]]

user446034

Posted 2016-10-25T23:57:54.160

Reputation: 131

3

Ruby / Brat, 26 bytes

#*
puts:treat
$*#p :trick

Ruby prints treat and Brat prints trick.

Ruby

The first line is a comment starting with #, so ignored. The second line prints out treat (the parser is liberal enough we don't need a space).

The last line is interpreted as $* (a global variable) and the rest is ignored as a comment starting with #.

Brat

In Brat, #* begins a multi-line comment and *# ends it.

The first line begins a multi-line comment, so the second line is ignored.

Brat sees $ as part of the comment and *# closes the comment started above. That leaves p :treat to print out treat.

Justin

Posted 2016-10-25T23:57:54.160

Reputation: 131

3

Actually and Python 2, 21 bytes

thanks to quartata for this solution

print"trick"#X"treat"

Try it online: Actually, Python 2

Explanations

Actually:

print"trick"#X"treat"
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"#X"treat"
print"trick"           # print "trick"
            #X"treat"  # a comment

Mego

Posted 2016-10-25T23:57:54.160

Reputation: 32 998

1print"trick"#X"treat" is shorter but much more boring. – a spaghetto – 2016-10-31T20:45:51.807

3

Ruby / ECMA6 27 bytes

{'t':'trick'}['t']||'treat'

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

a={'t':'trick'};a['t']||'treat'

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.

Yule

Posted 2016-10-25T23:57:54.160

Reputation: 131

Cool trick! I'm not sure if this qualifies as a full program/function though :(. – m-chrzan – 2016-10-27T13:40:15.133

3

Python/Brainf**k (87 Bytes)

print("treat")#+++++++++[>+++++++++<-]>+++.--.<+++[>---<-]>.<++[>---<-]>.<++++[>++<-]>.

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

chin123

Posted 2016-10-25T23:57:54.160

Reputation: 31

3

Pyth and SMBF, 28 bytes

"trick"<.q<.q<.q<.q<.q"taert

"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).

Steven H.

Posted 2016-10-25T23:57:54.160

Reputation: 2 841

2I appreciate the game you've set up, but can you remove the spoiler from the title please? :) – Beta Decay – 2016-10-28T06:09:35.627

3

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.

ninjalj

Posted 2016-10-25T23:57:54.160

Reputation: 3 018

3

C / C++, 73 bytes

#include<stdio.h>
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().

Keith Thompson

Posted 2016-10-25T23:57:54.160

Reputation: 289

1We 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. – Dennis – 2016-11-03T20:34:00.473

3

C / C++, 72 bytes

#include<stdio.h>
main(){char*a[]={"trick","treat"};puts(a[1//**/2
]);}

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]);.

The Vee

Posted 2016-10-25T23:57:54.160

Reputation: 771

3

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

(Function[Slot[1]])[treat]

and evaluates to treat.

The Vee

Posted 2016-10-25T23:57:54.160

Reputation: 771

3

C / Javascript, 70 47 bytes

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

/**\
/main(){puts("trick");}
//*/alert("treat")

What C sees:

main(){puts("trick");}

What javascript sees:

alert("treat")

Explanation:

/* 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 */ 

technosaurus

Posted 2016-10-25T23:57:54.160

Reputation: 231

3

Windows Batch, JScript, 35 bytes

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

The batch version displays the parentheses as delimiters.

peter ferrie

Posted 2016-10-25T23:57:54.160

Reputation: 804

This outputs (trick) instead of trick. – Ismael Miguel – 2016-10-30T05:24:32.330

yes, the batch version displays the parentheses as delimiters. – peter ferrie – 2016-11-01T19:50:33.467

Actually, batch displays whatever you write after. In this case, it will show (trick). If you wrote "trick", it would show that. – Ismael Miguel – 2016-11-01T23:32:22.297

but then it won't be valid JavaScript, which requires the parentheses to run the function. – peter ferrie – 2016-11-02T16:45:11.040

Can you use backticks? – Ismael Miguel – 2016-11-02T18:16:51.217

no, must be parentheses because I am targeting the console environment, not the web one. Naming the environment should really be a rule - calling it JavaScript alone isn't sufficient to identify the execution environment. – peter ferrie – 2016-11-07T18:29:40.170

Oh, sorry. I mixed Javascript (ES6) with JScript. Those are different. Sorry. Well, you did all you could with what you have. I will praise it. – Ismael Miguel – 2016-11-07T20:23:35.030

3

Windows Batch, VBScript, 34 bytes

trick="treat":WScript._
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.

peter ferrie

Posted 2016-10-25T23:57:54.160

Reputation: 804

Can you explain how this works ? – FliiFe – 2016-10-31T09:42:55.523

@FliiFe, updated my answer. – peter ferrie – 2016-11-01T19:55:43.877

3

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.

Zatherz

Posted 2016-10-25T23:57:54.160

Reputation: 111

3

HTML/Foo, 19 15 12 bytes

trick<"treat

Displays trick in HTML and prints treat in Foo.

user8397947

Posted 2016-10-25T23:57:54.160

Reputation: 1 242

3

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.

Keith Thompson

Posted 2016-10-25T23:57:54.160

Reputation: 289

1bash has interactive_comments shoptand zsh hasINTERACTIVE_COMMENTS` to control this behaviour. – ninjalj – 2016-11-03T01:28:02.633

3

HTML / JavaScript (ES6), 28 bytes

trick<alert`treat`;var trick

Test HTML | Test JS

Explanation

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.

ETHproductions

Posted 2016-10-25T23:57:54.160

Reputation: 47 880

3

Labyrinth/Perl, 38 bytes

As cat -v:

$_=116.114.105.99.107.$@^"^@^@^L^B^_";print

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  |$_=116.114.105.9|
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|
00000026

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
116.114.105.99.107.    → print string
$                      → dummy op
@                      → end

while Perl does:

$_=                    → set the $_ variable to:
 116.114.105.99.107    →  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:

; $_=116.114.105.99.107.$@
; ;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:

; $_=116.114.101.97.116.$@
; ;     ;       +  +      
; ;;;;;;;;;;;;;;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):

25^25^25^23^0;$;=116.114.105.99.107.$@
        ; print$    ;   ;  1+ 7+ 16
;

Labyrinth/Perl, boring version, 49 bytes

Separate code paths for Labyrinth and Perl:

;print 116.114.105.99.107
;
116.114.101.97.116.$@

ninjalj

Posted 2016-10-25T23:57:54.160

Reputation: 3 018

3

Haskell / Ruby, 74 bytes

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

Haskell

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".

Ruby

--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.

ignite

Posted 2016-10-25T23:57:54.160

Reputation: 131

Welcome to the site! – James – 2016-11-03T16:14:11.027

2

C / Octave, 63 bytes

#define f() main(){puts("trick");}//\
f=@()(disp("treat"));
f()

Explanation:

What C sees:

#define f() main(){ puts("trick"); } //comment
f()

What Octave sees:

#comment
f = @()(disp("treat"));
f()

Pretty straightforward.

tonychow0929

Posted 2016-10-25T23:57:54.160

Reputation: 241

2

Excel / Google Sheets, 28 Bytes

Anonymous worksheet formula that takes no input and outputs "Trick" to the calling cell in Excel and "Treat" to the calling cell in Google Sheets

=IfError(M("Treat"),"Trick")

Taylor Scott

Posted 2016-10-25T23:57:54.160

Reputation: 6 709

2

Javascript/Ruby, 35 30 bytes

0?puts("trick"):alert("treat")

0 is truthy in Ruby, but not in Javascript.

Edit: Saved 5 bytes by replacing []==[] with 0.

aaay aaay

Posted 2016-10-25T23:57:54.160

Reputation: 71

As far as I know, JS doesn't compare by value. It compares if it's the same object, which it is not, as you are initializing two different empty arrays. – BrainStone – 2018-01-17T17:15:36.023

2

Haskell and ink, 31 or 42 29 bytes

trick/*b=b
main=putStr"treat"

Try it online! (Haskell, ink)

Explained

Ink doesn't mind unclosed multiline comments, so as far as ink is concerned, the program is just trick, which gets printed literally.

Haskell interprets the first line as defining a function /* that takes two parameters named trick and b and returning the latter. main just prints "treat"

Sara J

Posted 2016-10-25T23:57:54.160

Reputation: 2 576

2

Runic Enchantments (treat) & Gol><> (trick), 15 bytes

"kcirt"H>'ອE@

Try it online! (Runic)

Try it online! (Gol><>)

The Gol><> is pretty straight forward. It pushes the char-literals for "trick" in reverse order, then H causes the entire stack to be dumped to output before terminating.

Runic starts at the >, pushes the char-literal (decimal value 3757) and calls E which causes a dictionary lookup on 3757, which is "treat", @ dumps stack and terminates.

Draco18s no longer trusts SE

Posted 2016-10-25T23:57:54.160

Reputation: 3 053

2

Forth (gforth) / Python 3, 32 bytes

0. # ." trick"
( print("treat"))

Try it online: (gforth, python)

Explanation

Not the most clever approach, effectively uses the different comment styles to have each language run its own code.

# starts a line comment in python, but adds the lowest digit of a double-length number to an output string in forth. 0. is used as the double-length number in forth, but unused in python

Standalone parentheses are used for grouping in python (and are ignored when unneeded), while they denote a block comment in forth.

reffu

Posted 2016-10-25T23:57:54.160

Reputation: 1 361

2

Whitespace / Lost, 112 bytes

v<<<<<<<<<<<>> > > >    >>>>>>
>%?"TRICv+"-+@> > > >        >
                 ^
        ^
    ^
^
  ^
                ^
        ^
  ^
 ^
^
^

Try it online in Lost : TRICK or verify that it's deterministic.
Try it online in Whitespace : TREAT.

Explanation for Lost

Explanation of the language in general:

Lost is a 2D path-walking language. Most 2D path-walking languages start at the top-left position and travel towards the right by default. Lost is unique however, in that both the start position AND starting direction it travels in is completely random. So making the program deterministic, meaning it will have the same output regardless of where it starts or travels, can be quite tricky.

A Lost program of 2 rows and 5 characters per row can have 40 possible program flows. It can start on any one of the 10 characters in the program, and it can start traveling up/north, down/south, left/west, or right/east.

In Lost you therefore want to lead everything to a starting position, so it'll follow the designed path you want it to. In addition, you'll usually have to clean the stack when it starts somewhere in the middle.

Explanation of the program:

Let's ignore everything except for the first two lines. The other lines all point upward/north, to lead the flow towards the following part of the code. (NOTE: The small t are actually tabs (\t). But due to alignment it's better readable like this.)

v<<<<<<<<<<<>> > > >t>>>>>>
>%?"TRICv+"-+@> > >t>t  t >

All the arrows lead towards the leading > of the second line. A minor thing to note about the arrows:

v<<<<<<<<<<<>> > > >t>>>>>>

could also have been:

v<<<<<<<<<<<<< < < <t<<<<<<

Lost programs will wrap around in all directions; i.e. when it goes out of bounds at the left-hand side traveling in a west/left direction, it continues at the right-hand side in that same direction. Because of this, using <<<>>> will have a shorter path and is therefore slightly better for performance than <<<<<<, and since it doesn't affect the byte-count anyway, why not use it. :)

An additional minor note: these alternating trailing parts are there because we need to fit the spaces/tabs of the Whitespace program in it:

 > > >t>>>>>>
> > >t>t  t >

So, all those arrows, including the v after the C in the string (more on that in a moment), will lead to the leading > on the second line. After that, the program flows and execution is as follows:

  • >: travel in an east/right direction
  • %: Put the safety 'off'. In a Lost program, an @ will terminate the program, but only when the safety is 'off'. When the program starts, the safety is always 'on' by default, otherwise a program flow starting at the exit character @ would immediately terminate without doing anything. The % will turn this safety 'off', so when we now encounter an @ the program will terminate (if the safety is still 'on', the @ will be a no-op instead).
  • ?: Clean the top value on the stack. In some program flows it's highly likely we have a partial string on the stack, so we use this to wipe the stack clean of that potential string.
  • ": Start a string, which means it will push the integer code-points of the characters used (rather similar as the Whitespace program).
  • TRICv+: Push the code-points for these characters, being 84 82 73 67 118 43 respectively
  • ": We're done pushing code-points of this string
  • -+: Subtract the top two values from each other, so the 118 43 becomes 75 (K). (NOTE: -+ are actually two loose operands: - will negate the top value on the stack (multiply it by -1), and + will add the top two values on the stack together.)
  • @: Terminate the program if the safety is 'off' (which it is at this point). After which all the values on the stack will be output implicitly. Using the -A program argument flag these code-points will be output as characters instead.

Explanation for Whitespace:

Explanation of the language in general:

Whitespace is a stack-based language using only spaces (), tabs (\t), and newlines (\n) (hereafter indicated with STN respectively). Any other character is ignored. Printing in Whitespace can either be done as character or as integer. When it outputs as character, it will use an integer on the stack as code-point and convert it to its corresponding UTF-8 character before outputting.

Integers are pushed to the stack as follows:

  • S: Enable Stack Manipulation
  • S: Push what follows as integer to the stack
  • S/T: Sign bit where S is positive and T is negative
  • Some T and S followed by an N: Put number as binary to the stack (T=1 and S=0)

For example: SSSTSTSN will push 10 to the stack.

Explanation of the program:

If we ignore all non-whitespace characters, the program will be this:

SSSTN           # Push 1     (T)
SSTTSSTSN       # Push -18   (A)
SSTTTTSN        # Push -14   (E)
SSTTN           # Push -1    (R)
SSSTN           # Push 1     (T)
NSSN            # Create Label LOOP
  SSSTSTSSTTN   #   Push 83
  TSSS          #   Add top two values on the stack together
  TNSS          #   Pop and output top of the stack as character with this code-point
  NSNN          #   Jump to Label LOOP

Instead of directly pushing and printing each character, I push all characters to the stack in reversed order, with each of their code-points lowered by a constant value. In a loop I then add this constant to the integer, before popping and outputting it as character. See this Whitespace tip of mine for more information on this approach.
The constant 83 is the most efficient constant for this output-text, which is generated by this Java program, a generator I've created and used for some of my other Whitespace answers in the past.

Kevin Cruijssen

Posted 2016-10-25T23:57:54.160

Reputation: 67 575

2

Keg / Foo, 14 bytes

("Treat")Trick

Try it online!

Try It online!

Explanation

Foo

("Treat")      Push "Treat"
         Trick NOPS
               Implicit print

Keg

("Treat")      # For loop over stack length. Stack is empty, therefore it is skipped.
         Trick # Push "Trick"
               # Implicit print

user85052

Posted 2016-10-25T23:57:54.160

Reputation:

2

Python 2 and C, 93 bytes

It's not exactly a competitive entry, but it was certainly a fun challenge. The Python section prints trick while the C portion prints treat.

#include <stdio.h>/*
print'trick'
#*/
#define pass int main(){puts("treat");return 0;}
pass

James Murphy

Posted 2016-10-25T23:57:54.160

Reputation: 267

2

C / Shell 57 50 bytes

Should be more verbose to match the C99 (missing include, no return value in main etc). But it runs fine with gcc, clang and tcc:

Updated version:

#define echo main(){puts("trick");}int
echo treat;

Initial version:

#define echo main(){puts("trick");}void*p=
echo "treat";

zserge

Posted 2016-10-25T23:57:54.160

Reputation: 121

this could be shortened to #define echo main(){puts("trick");}int and echo treat; – technosaurus – 2016-10-29T05:17:26.393

@technosaurus Might work in some compilers, but gcc throws an error - not a constant initializer. – zserge – 2016-10-29T11:01:13.510

I didn't have an = sign, so it shouldn't complain about an initializer. After preprocessing, C should see echo main(){puts("trick");}int treat;... which is just an unused (and uninitialized) variable named treat ... I think you may have added an equal sign to the end of the #define block. ... which brings it down to 50 bytes. – technosaurus – 2016-10-29T17:52:27.427

1You don't need int in C89; a bare treat; will default to int. – Dennis – 2016-10-30T04:03:02.807

2

QBIC and QBasic 4.5, 45 bytes

QBIC is my attempt at a golfing language, based on QBasic. The language has evolved quite a bit from its original, as I think this snippet illustrates:

A$=STR$(q):IF A$=" 1"THEN?"trick"ELSE?"treat"

The space before the 1 is significant. QBIC will print trick, QBasic will show treat. So, what's going on here. First, QBasic:

A$=STR$(q)          Set A$ to a string representation of the number q                        
IF A$=" 1"          A$ is now " 0" because 'q' is not set and 0 by default.
                    Space added by STR$ :'(  
THEN PRINT "trick"  Ignored
ELSE PRINT "treat"  Printed

Now QBIC. This one is a little more complex:

A                   Creates A$ in te output BAS
$                   Start a Code Literal. QBIC is not yet very function-complete,
                    so on occasion we need to call QBASIC functions directly. However,
                    that may interfere with QBIC syntax. When a '$' is encountered,
                    QBIC ignores everything from that $ until a '|' or EOF and
                    just passes this along as QBASIC.  
=STR$(q)            Set A$ to a string representation of the number q                        
IF A$=" 1"          A$ is now " 1" because 'q' is pre-initilised to 1 by QBIC                       
THEN PRINT "trick"  printed
ELSE PRINT "treat"  ignored

We don't need END-IFs, because in the snippet the IF is in-line.

steenbergh

Posted 2016-10-25T23:57:54.160

Reputation: 7 772

2

Dart - JavaScript (68 bytes)

Seems appropriate as Google has been livestreaming the Dart Developer Summit for the past two days.

var a=main();function main(){1==true?alert("Treat"):print("Trick");}

Formatted:

var a = main();

function main() {
  1 == true ? alert("Treat") : print("Trick");
}

main method

In Dart static variables may only be initialized with compile-time constants (hereafter referred to as just constants in the interest of brevity). Static variables include all top-level variables as well as static variables of classes.

^ http://news.dartlang.org/2012/02/static-variables-no-longer-have-to-be.html

The Dart VM starts by immediately calling the main method. As the variable 'a' is a top level one, the Dart VM will only initialize it when it's needed (lazy initialization).

JavaScript immediately initializes the variable by which the main method also gets invoked.


truthy/falsey

Dart differs from JavaScript in its treatment of truthy and falsey values. In JavaScript, the objects 1, non-empty string, and non-null objects are treated as true. In Dart, it’s more simple. Only the boolean value true is treated as true. In Dart, all object instances other than true are treated as false.

^ https://www.dartlang.org/resources/dart-tips/dart-tips-ep-4

The above quote explains why 1 == true evaluates to true in JavaScript whilst it gets evaluated to false in Dart.

Jasper Catthoor

Posted 2016-10-25T23:57:54.160

Reputation: 51

Couldn't you just use 1? instead? And at least in JavaScript you can get rid of the outer most parentheses. I don't know about dart though – BrainStone – 2016-10-27T18:37:15.313

@BrainStone nope. As Dart requires a static type of bool for conditions, you can't just use integer ? : – Jasper Catthoor – 2016-10-27T19:11:34.697

@BrainStone you're right about the outer most parentheses though! Thanks for the heads up – Jasper Catthoor – 2016-10-27T19:12:20.320

2

C / JavaScript (75 bytes)

Works with Clang on Mac, with some warnings, and Node.js.

main()
{puts("trick");}//\
function main(){puts=()=>console.log("treat");}

75 bytes is quite a bit but JavaScript is a verbose language for code golf.

I took inspiration from I_LIKE_BREAD7 for the escaped comment line to include non-C code in a .c file.

user61383

Posted 2016-10-25T23:57:54.160

Reputation:

2

64 bytes: //\\nmain=_=>{puts=_=>console.log`treat`}\nmain()\n{puts("trick");} (replace all \n with a REAL newline.) Example in C (http://ideone.com/YToPEb) and in Javascript (https://jsfiddle.net/1m2yfdow/).

– Ismael Miguel – 2016-11-01T23:44:49.873

1

I've actually reduced it to 62 bytes: //\\nmain=_=>{puts=_=>console.log`treat`}\nmain()\n{puts("tr‌​ick");}. All I did was replacing main=_=>{puts=_=>console.log`treat`} with main=_=>puts=_=>console.log`treat`. Try it on https://jsfiddle.net/1m2yfdow/1/. This is a Javascript-only change, so, C won't be affected

– Ismael Miguel – 2016-11-02T17:27:22.150

2

Python, Lua 31 or 32 bytes

s="trick"
--0;s="treat"
print s

The one above has to be run using python 2.

s="trick"
--0;s="treat"
print(s)

The -- designates a comment in Lua, while it is two negatives in Python. Prints "trick" in Lua, but prints "treat" in Python.

Zacharý

Posted 2016-10-25T23:57:54.160

Reputation: 5 710

2

Python / JavaScript, 32 bytes

1//2;print"trick"
alert("treat")

Python runs 1//2;, which integer divides 1 by 2, then prints "trick". alert("treat") causes a runtime error because alert is not a function, but I believe this is allowed.

JavaScript runs 1 and sees the rest of the line as a comment. The second line alerts "treat".

Note that I can't shorten alert("treat") to alert`treat` because Python will throw a syntax error during compilation.

ETHproductions

Posted 2016-10-25T23:57:54.160

Reputation: 47 880

2

Lua, Ruby - 31 bytes

s="trick"
--0;s="treat"
print s

The explanation is the same as my Python/Lua answer. Prints treat in Ruby, trick in Lua.

Zacharý

Posted 2016-10-25T23:57:54.160

Reputation: 5 710

2

Clojure/Groovy, 37 bytes

;/*
(println"trick");*/println"treat"

Clojure (trick)

The ; denotes a single-line comment, so Clojure sees:

(println "trick")

Groovy (treat)

Any single ; is a valid statement that does nothing. Obviously /* ... */ is a multi-line comment. Groovy sees:

println "treat"

Ryan Evans

Posted 2016-10-25T23:57:54.160

Reputation: 21

2

Python / Japt, 22 bytes

1
print"trick";"treat"

Python

This should be fairly obvious: print"trick" prints trick; 1 and "treat" don't do anything.

Japt

This code transpiles to

1
.p("r".i("n".t(("trick"))));("treat")

The result of last expression is automatically sent to STDOUT, so this prints treat.

ETHproductions

Posted 2016-10-25T23:57:54.160

Reputation: 47 880

2

Cubix / Japt, 24 bytes

WHAT"kcirt"u@!C;Co} `É.t

Test Cubix | Test Japt

The . represents the unprintable char U+0084.

Japt

Before running Japt code, it is first transpiled to JavaScript. The various features transpile roughly to:

WHAT    "kcirt"u  @               !C;       Co      `É.t
W,H,A,T,"kcirt".u(function(X,Y,Z){!C;return C.o()}),"treat"

The the code is evaluated, and the result of the last expression is sent to STDOUT. W,H,A,T are variables, but they're effectively no-ops since we don't do anything with them. "kcirt".u() makes the string uppercase, ignoring the function, but again, this is discarded. The only thing that matters is the "treat" at the end; this is printed, end then the program ends.

Cubix

Before the code is run, all whitespace is removed, and the code is transformed into the smallest cube net possible, padded with . no-ops. This particular program becomes:

    W H
    A T
" k c i r t " u
@ ! C ; C o } `
    É .
    t .

Then the code is run like a regular 2D language, with the IP (instruction pointer) starting at the top-left corner of the leftmost face. Here's what happens:

  • "kcirt" - Push the char codes of these letters to the stack.
  • u - Make a U-turn to the right, going down a row in the process.
  • ` - Not implemented, so a no-op.
  • } - Another no-op.
  • o - Output the char-code on top of the stack (t).
  • C - Another no-op.
  • ; - Remove the top item.
  • C - Another no-op.
  • ! - If the top item is non-zero, skip the next instruction (@).

Since the top item is non-zero, the IP jumps the @ and wraps back around to the `. This repeats until the last character has been outputted, at which point ! fails and the IP hits @, ending the program.


Old solution, 25 bytes

"treat"//"kcirt"under@!;o

Test Cubix | Test Japt

Japt

This is very simple: // and everything after is a comment, so the only thing evaluated is "treat". This is implicitly printed to STDOUT.

Cubix

The code is expanded to the following cube net:

      " t r
      e a t
      " / /
" k c i r t " u n d e r
@ ! ; o . . . . . . . .
. . . . . . . . . . . .
      . . .
      . . .
      . . .

Then the code is run like a regular 2D language, with the IP (instruction pointer) starting at the top-left corner of the leftmost face. Here's what happens:

  • "kcirt" - Push the char codes of these letters to the stack.
  • u - Make a U-turn to the right, going down a row in the process.
  • .... - A bunch of no-ops.
  • o - Output the char-code on top of the stack (t).
  • ; - Remove the top item.
  • ! - If the top item is non-zero, skip the next instruction.

The IP then wraps around to the right, so these last 3 instructions repeat until the stack is empty. Then ! fails, so the IP lands on @, which ends the program. The Japt code is conveniently contained on the top face and never gets run.

ETHproductions

Posted 2016-10-25T23:57:54.160

Reputation: 47 880

1

SmileBASIC / ><>, 21 bytes

'kcirt'ooooo;
?"treat

Try the ><> one here!

Sadly SmileBASIC doesn't have an online interpreter.

SmileBASIC Explanation

'kcirt'ooooo; # `'` is a comment character in SmileBASIC, so this is ignored
?"treat       # `?` is an alias for "PRINT", the string doesn't need  to be closed

><> Explanation

'kcirt'        push "trick" to stack
       ooooo   output "trick"
            ;  end execution

redstarcoder

Posted 2016-10-25T23:57:54.160

Reputation: 1 771

1

C / C++, 99 bytes

#include<stdio.h>
#if __cplusplus
#define puts(x) puts("treat")
#endif
main(){puts("trick");}

it is quite long, but i am wondering why there had not be one.

tsh

Posted 2016-10-25T23:57:54.160

Reputation: 13 072

But there is: https://codegolf.stackexchange.com/a/97677/44874 ...

– steenbergh – 2017-04-18T05:56:22.343

@steenbergh Duplicate answers are allowed. – Erik the Outgolfer – 2017-04-18T14:05:49.467

1

PHP and PowerShell - 38 bytes

if($_ENV){echo "trick";}return "treat"

It's not that clever. Just makes use of the similarities between PHP and PowerShell

SomeShinyObject

Posted 2016-10-25T23:57:54.160

Reputation: 953

1

C / Common Lisp, 95 92 44 40 bytes

//(princ"trick")
;main(){puts("treat");}

Try C online!

Try Common Lisp online!

Both “normal” languages with very different syntax and semantics.

Explanation

For Common Lisp:

// is a special variable used in the Common Lisp REPL to give the result of the value preceding the previous one, initially equal to NIL. Then we print trick. The following line starts with ; and this in Commonl Lisp is considered a comment.

For C, the first line is a comment, and the other is the program. Note that the semicolon before the definition of the main function is syntactically correct.

Renzo

Posted 2016-10-25T23:57:54.160

Reputation: 2 260

1

Clojure/Script

Clojure

(prn (if (= (str (type "")) "class java.lang.String") "trick" "treat"))

ClojureScript

(prn (if (= (str (type "")) "class java.lang.String") "trick" "treat"))

Explanation

Clojure compiles down to JavaScript, and works quite the same as it does in Java.

"class java.lang.String" is not available in JavaScript, but, the if statements and prn work exactly the main.

Chris Etheridge

Posted 2016-10-25T23:57:54.160

Reputation: 11

1

Dart, Dart2JS, 49 bytes

main(){print(identical(1,1.0)?"Treat":"Trick");}

running by dart gives:

$ dart web/test.dart 
Trick

for compiled version:

$ dart2js web/test.dart
$ nodejs out.js
Treat

Vaulter

Posted 2016-10-25T23:57:54.160

Reputation: 11

1Hello, and welcome to PPCG! This question is [tag:code-golf], so please include the number of bytes in your code, and the two languages (dart2js, dart) that you use. Also, please remove extra spaces in your code. – NoOneIsHere – 2016-10-27T18:21:07.397

1

/// / ><>, 29 bytes

/v//treat/
"l
t?
r!
i;
co
k
"

Try /// online. This prints treat after it replaces all vs with null, then stops processing because of the single / which does not complete a /// block.

Try ><> online. Gives us trick. The first / wraps execution around to the " on line 8, it pushes trick onto the stack in reverse order, bounces off of the first / again, goes down at the v and uses a loop to print all the stacked characters LIFO.

steenbergh

Posted 2016-10-25T23:57:54.160

Reputation: 7 772

Hi, would you mind to change the header to # /// / ><>, 29 bytes? This is so that leaderbaord snippet doesn't get confused. – BrainStone – 2018-01-17T13:32:20.187

1

/// / ><>, 22 bytes

\treat/
>"kcirt"ooooo;

Try it online! Slashes | Fish

Explanation

(♥ is a newline)

  • ///

    \t                      Print "t"
      reat                  Print "reat"
          /♥>"kcirt"ooooo;  Incomplete replacement, ignored
    
  • ><>

    \                       Mirror, makes IP go down
           ♥>               Go right
             "kcirt"ooooo   Print "trick"
                         ;  End program
    

acrolith

Posted 2016-10-25T23:57:54.160

Reputation: 3 728

1

CJam/Befunge, 21 bytes

"Trick"o"taerT",,,,,@

Try it online! (CJam)
Try it online! (Befunge)


CJam:

"Trick"o push "Trick" and print it.
"taerT", push "taerT" and take length, 5.
,,,, take lengths of ranges, leaves 5.
@ tries to rotate top three elements.

CJam would normally print the stack on exit, but with only a single element the rotation causes an empty stack exception and the 5 is left unprinted.

Befunge:

"Trick" push each letter of "Trick".
o is unspecified and gets ignored.
"taerT" push each letter of "Treat" in reverse.
,,,,, pop and print 5 letters ("Treat")
@ terminates Befunge naturally.

Befunge doesn't print the stack on exit so the letters from "Trick" don't cause a problem. However, the unspecified o may be treated differently on other interpreters. For instance this one would reverse the instruction pointer and wrap back to @ with no output.

Linus

Posted 2016-10-25T23:57:54.160

Reputation: 1 948

1

Scheme / Brainf*ck, 80 bytes

My second attempt.

(print 'trick);++++[>+++++[>+++++<-]<-]>>[>+>+<<-]++++[>++++<-]>.--.>+.----.<++.

What Scheme sees: (print 'trick)

What Brainf*ck sees: ++++[>+++++[>+++++<-]<-]>>[>+>+<<-]++++[>++++<-]>.--.>+.----.<++.

Happy Halloween.

user61383

Posted 2016-10-25T23:57:54.160

Reputation:

1

JavaScript (with SpiderMonkey print)/Python - 32 bytes

a=1
print(["trick","treat"][--a])

Zacharý

Posted 2016-10-25T23:57:54.160

Reputation: 5 710

Would a=1;print(["trick","treat"][--a]) work instead? – ETHproductions – 2016-11-03T20:48:30.000

Yes, that works! – Zacharý – 2016-11-03T21:07:23.043

0

JavaScript/Ruby - 32 bytes

(Assuming Spidermonkey-like output function print)

a=1
print(["trick","treat"][--a])

Ruby -- is double negative, while in JavaScript it is decrement;

Zacharý

Posted 2016-10-25T23:57:54.160

Reputation: 5 710

0

JavaScript (Spidermonkey print) (treat), Python (trick) - 34 bytes

a=1//2
print(["trick","treat"][a])

// is a comment in JavaScript, and truncating integer division in Python.

Zacharý

Posted 2016-10-25T23:57:54.160

Reputation: 5 710

http://codegolf.stackexchange.com/a/98219/42545 I don't mind if you keep this, though, as the other one is browser JS. – ETHproductions – 2016-11-03T20:47:42.483