165
\$\begingroup\$

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>

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

128 Answers 128

9
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ @jmathews Have you tried putting a backspace control character into your windows version? What about CLS? \$\endgroup\$
    – Titus
    Commented Oct 26, 2016 at 12:13
  • \$\begingroup\$ ` is the truthy value of defined&x or d&x ask me not which d you get \$\endgroup\$ Commented Oct 27, 2016 at 16:37
9
\$\begingroup\$

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
\$\endgroup\$
2
  • 2
    \$\begingroup\$ Couldn'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 \$\endgroup\$
    – xenia
    Commented Oct 26, 2016 at 5:22
  • 1
    \$\begingroup\$ To add to @Loovjo's comment, n fails as it has no second operand. \$\endgroup\$ Commented Oct 26, 2016 at 6:22
9
\$\begingroup\$

/// / 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"
    
\$\endgroup\$
2
  • \$\begingroup\$ You can replace console.log with alert to save some bytes. \$\endgroup\$
    – BrainStone
    Commented Oct 26, 2016 at 17:10
  • \$\begingroup\$ 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. \$\endgroup\$
    – steenbergh
    Commented Oct 27, 2016 at 8:54
8
\$\begingroup\$

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

\$\endgroup\$
0
7
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ You can skip the ; if you error out in fish. \$\endgroup\$
    – Emigna
    Commented Oct 26, 2016 at 9:20
7
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ I'm not a Perl expert, but can you use barewords and drop the quotes from ick and eat? Also, is my necessary? \$\endgroup\$
    – DLosc
    Commented Oct 27, 2016 at 2:49
  • \$\begingroup\$ The quotes and my are necessary in Perl 6, but not in Perl 5. \$\endgroup\$
    – bb94
    Commented Nov 4, 2016 at 2:03
7
\$\begingroup\$

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

\$\endgroup\$
2
  • \$\begingroup\$ You can replace 1e100==10**100 with 1/2>0 (if you're using Python 2) \$\endgroup\$
    – acrolith
    Commented Oct 30, 2016 at 18:46
  • \$\begingroup\$ @daHugLenny Cool, thanks :) I'll improve the solution! \$\endgroup\$ Commented Oct 30, 2016 at 19:12
6
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ What is FOG? I have not heard of that language. \$\endgroup\$ Commented Oct 26, 2016 at 1:02
  • 1
    \$\begingroup\$ @ETHproductions FOG, or Fuzzy Octo Guacamole, is his language. \$\endgroup\$ Commented Oct 26, 2016 at 1:12
  • \$\begingroup\$ Actually, X is eval'd input. Subtle difference. \$\endgroup\$ Commented Oct 26, 2016 at 1:21
  • \$\begingroup\$ @ConorO'Brien eh, close enough. Will edit with links also. \$\endgroup\$
    – Riker
    Commented Oct 26, 2016 at 1:25
6
\$\begingroup\$

Dip/05AB1E, 15 bytes

"trick"q"treat"

Prints treat in Dip and trick in 05AB1E.

\$\endgroup\$
1
  • 11
    \$\begingroup\$ My brain read the header as "Disposable." :P \$\endgroup\$
    – DLosc
    Commented Oct 26, 2016 at 20:01
6
\$\begingroup\$

Clip and Wake, 15 bytes

15 bytes

Guess what the two languages are.

"trick":"treat"
\$\endgroup\$
0
6
\$\begingroup\$

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

\$\endgroup\$
6
\$\begingroup\$

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)
\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Oct 29, 2016 at 2:13
  • \$\begingroup\$ @ETHproductions Wow, didn't know Japt could do that. Honestly, only found out about the language in the writing of this entry xD \$\endgroup\$
    – user36219
    Commented Oct 29, 2016 at 6:23
5
\$\begingroup\$

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

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to PPCG! Nice first post! \$\endgroup\$
    – Riker
    Commented Oct 26, 2016 at 12:14
5
\$\begingroup\$

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

\$\endgroup\$
5
\$\begingroup\$

TI-Basic / BF, 49 bytes

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

"-[--->+<]>-.--.---------.------.++++++++.
"TREAT
\$\endgroup\$
5
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ Note sizeof'a' works and saves you 2 bytes! In fact, I considered the prefix trick, and it actually costs more than it saves. \$\endgroup\$
    – BoBTFish
    Commented Oct 27, 2016 at 9:37
  • \$\begingroup\$ @BoBTFish Old habits of being careful die hard. \$\endgroup\$
    – Art
    Commented Oct 27, 2016 at 9:38
  • \$\begingroup\$ Didn't really go for golfing this, rather for obfuscation. puts(sizeof'a'-1?"treat":"trick") is shorter, but it's boring. \$\endgroup\$
    – Art
    Commented Oct 27, 2016 at 9:43
5
\$\begingroup\$

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'
\$\endgroup\$
0
5
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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
\$\endgroup\$
3
  • \$\begingroup\$ Are you sure if the CSS is valid if you need the HTML? \$\endgroup\$ Commented Nov 27, 2016 at 1:07
  • \$\begingroup\$ @SolomonUcko Most browsers imply <html></html> tags, and * matches every element, including html. \$\endgroup\$
    – corvus_192
    Commented Nov 27, 2016 at 16:18
  • \$\begingroup\$ Good point. I just got confused when you changed it to a p tag in the explanation \$\endgroup\$ Commented Nov 27, 2016 at 16:42
5
\$\begingroup\$

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

\$\endgroup\$
0
5
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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
\$\endgroup\$
5
\$\begingroup\$

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 !

\$\endgroup\$
4
  • \$\begingroup\$ 113 bytes unless I'm missing something. \$\endgroup\$
    – Linus
    Commented Oct 31, 2016 at 6:13
  • \$\begingroup\$ Yep, I had put an extra linefeed when couting. Thanks \$\endgroup\$
    – THC
    Commented Oct 31, 2016 at 9:34
  • \$\begingroup\$ In case you want to add them, here are permalinks for Befunge and Whitespace. \$\endgroup\$
    – Dennis
    Commented Nov 25, 2016 at 0:37
  • \$\begingroup\$ @Dennis Added them. Thanks ! \$\endgroup\$
    – THC
    Commented Nov 26, 2016 at 18:08
5
\$\begingroup\$

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.

\$\endgroup\$
5
\$\begingroup\$

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!

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

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$
    – DLosc
    Commented Oct 27, 2016 at 2:51
4
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 'tr'+(/.*/=='ick'||'eat') is just 25 bytes, but seems it's not allowed as it isn't neither a function or a full program. \$\endgroup\$ Commented Oct 26, 2016 at 11:00
  • \$\begingroup\$ And /.*/=='trick'||'treat' is 22 ;) \$\endgroup\$ Commented Nov 1, 2016 at 15:18
4
\$\begingroup\$

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
\$\endgroup\$
4
\$\begingroup\$

/// / 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"
    
\$\endgroup\$

Your Answer

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

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