[Question]
      [
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 [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), 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>
```

[Answer]
# VBScript, JScript, 41 bytes
`x="treat"
rem=x="trick"
WScript.echo(x)`
The VBScript "rem" hides the JScript code.
[Answer]
# 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, `alert`s the item at index `a` in `["trick","treat"]`. Since `a` is `1`, this alerts `"treat"`.
[Answer]
## 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!)](http://perldoc.perl.org/perlsyn.html#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`.
[Answer]
# PHP, Lua 41 Bytes
PHP print trick an Lua treat
```
--$a;echo"trick";/*
print("treat")
--*/
```
[Answer]
# JavaScript (ES6) / [Japt](https://github.com/ETHproductions/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](http://ethproductions.github.io/japt/?v=master&code=MQphbGVydGB0cmlja2A7InRyZWF0Ig==&input=)
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.
[Answer]
# 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
```
[Answer]
# [///](https://esolangs.org/wiki////)/[D1ffe7e45e](https://esolangs.org/wiki/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.
[Answer]
# [Emoji](https://esolangs.org/wiki/Emoji)/[Emojicode](http://www.emojicode.org/), 50 bytes
```
üë¥üí¨tricküí¨‚û°
üèÅüçáüòÄüî§treatüî§üçâ
```
[Try Emoji online!](https://tio.run/##S83Nz8r8///D/IlbPsyftKakKDM5G8R4NG8h14f5/Y0f5ve2f5g/o@HD/ClLSopSE0tADKBg5///AA "Emoji ‚Äì Try It Online")
[Try Emojicode online!](https://tio.run/##S83Nz8pMzk9J/f//w/yJWz7Mn7SmpCgzORvEeDRvIdeH@f2NH@b3tn@YP6Phw/wpS0qKUhNLQAygYOf//wA "Emojicode ‚Äì Try It Online")
[Answer]
# 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!](https://tio.run/##yyrNyUw0/f8/xzZaqaQoMzlbSQdIpyaWKMVyFRRl5pVo5EQbxmr@/w8A "Julia 0.5 ‚Äì Try It Online")
[Try it online - Python!](https://tio.run/##K6gsycjPM/7/P8c2WqmkKDM5W0kHSKcmlijFchUUZeaVaOREG8Zq/v8PAA "Python 3 ‚Äì Try It Online")
[Answer]
# 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](https://tio.run/##hZA9D4MgEIb/ytXZMHVysoNDNxOnxjhc8WoJBY1CUn89hSamX2gHErh7H@7JTcPNuURyMZpkL9OclZbLlJXYUcoO3MAxYxUnTeFSF9rQCKEJqFsI2Sa8slNvQUxgrgSTVdBfAOEsuujhaJ70ZngJ4XuFVQOh9OAMSuh29zt19pUXNojuGwnKEVtF20r@p/XA0sTYwH@Oa57xrX6ykZXUxZ2sNo1zDw "Shakespeare Programming Language ‚Äì Try It Online") / [Befunge-98](https://tio.run/##hZA9D4IwEIb/ysmMnRyUSQcGNxMmQxiOctSmoRBoE/n1lZoQvwoOTdq79@k9uZJqqwVtD3vnIsVlb6Kdio/sYrmK2QUFxezEDZwTlnHS5C95qg314JuAugKfLfwrubYW5ADmRjDYBtoaEEopgoejedKr4TmE7xWWdYRqAkdopK42v1PHqfLCOim@Ea8csG1oXWn6aTkwNzE08J/jkmd4q59sYCV5eierTeHcAw "Befunge-98 ‚Äì Try It Online")
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.
[Answer]
# Scala / Javascript, 33 bytes
```
if(0==false)"trick"; else "treat"
```
`0==false` returns true in javascript, but false in scala
[Answer]
# 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.
[Answer]
## [Charcoal](http://github.com/somebody1234/Charcoal) and [Pip](http://github.com/dloscutoff/pip), 13 bytes
```
trick¬©"treat"
```
### Charcoal
Charcoal's [code page](https://github.com/somebody1234/Charcoal/wiki/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](http://charcoal.tryitonline.net/#code=dHJpY2vCuyJ0cmVhdCI&input=)
### 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](http://pip.tryitonline.net/#code=dHJpY2vCqSJ0cmVhdCI&input=)
[Answer]
# C/Lua, 65 bytes
```
#include<stdio.h>/*
print"trick"--[[*/
main(){puts("treat");}//]]
```
[Answer]
# 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.
[Answer]
# 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.
[Answer]
# 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.
[Answer]
# 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]);`.
[Answer]
# 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`.
[Answer]
# 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 */
```
[Answer]
# Windows Batch, JScript, 35 bytes
`trick="treat";WScript.
echo (trick)`
The batch version displays the parentheses as delimiters.
[Answer]
# 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.
[Answer]
# 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`).
>
>
>
[Answer]
# [Actually](http://github.com/Mego/Seriously) and Python 2, 21 bytes
*thanks to quartata for this solution*
```
print"trick"#X"treat"
```
Try it online: [Actually](http://actually.tryitonline.net/#code=cHJpbnQidHJpY2siI1gidHJlYXQi&input=), [Python 2](http://ideone.com/Wb145I)
## 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
```
[Answer]
# 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.
[Answer]
# HTML / JavaScript (ES6), 28 bytes
```
trick<alert`treat`;var trick
```
[**Test HTML**](https://jsfiddle.net/d6nqg24c/) | [**Test JS**](https://jsfiddle.net/d6nqg24c/1/)
## 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.
[Answer]
**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.
[Answer]
# 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.
[Answer]
# 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()`.
[Answer]
# 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](https://codegolf.stackexchange.com/users/47066/emigna)'s [Labyrinth/><> answer](https://codegolf.stackexchange.com/a/97513/267). In that answer, Labyrinth code looks very much like it starts with a Perl [version string](http://perldoc.perl.org/perldata.html#Version-Strings).
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.$@
```
]


[Question]
      [
**This question already has answers here**:

[Palindromic palindrome generator](/questions/47827/palindromic-palindrome-generator)
 (39 answers)

Closed 7 years ago.
Your task is to palindromize a string as follows:
Take the string.
```
abcde
```
Reverse it.
```
edcba
```
Remove the first letter.
```
dcba
```
Glue it onto the original string.
```
abcdedcba
```
But here's the catch: since this challenge is about palindromes, **your code itself also has to be a palindrome.**
Remember, this is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the smallest number of bytes wins.

[Answer]
# Python 3, 41 bytes
```
lambda t:t+t[-2::-1]#]1-::2-[t+t:t adbmal
```
[Try it here](https://goo.gl/6W6SZX).
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 1 byte
```
√ª
```
[Try it online!](http://05ab1e.tryitonline.net/#code=w7s&input=YWJjZGU)
[Answer]
# Dip, 1 byte
```
B
```
Body must be at least 30 characters; you entered 13.
[Answer]
# Pyth - 13 bytes
It kinda looks like its crying.
```
+Qt_Q " Q_tQ+
```
[Try it online here](http://pyth.herokuapp.com/?code=%2BQt_Q+%22+Q_tQ%2B&input=%22abcde%22&debug=0).
[Answer]
# [ÏïÑÌù¨(Aheui)](http://esolangs.org/wiki/Aheui), ~~149~~ 137 bytes (47 chars + 2 newlines)
```
Î∂õÎ±êÏé§Î∂áÏé°ÎªêÏ≤òÏàúÏùòÏù¥Î©ìÌù¨
Îπ†Î≥∏Îï®Î≤åÎã§Îî∞ÌÜ†Î®ÄÏùòÏç©ÏÜçÏç©ÏùòÎ®ÄÌÜ†Îî∞Îã§Î≤åÎï®Î≥∏Îπ†
Ìù¨Î©ìÏù¥ÏùòÏàúÏ≤òÎªêÏé°Î∂áÏé§Î±êÎ∂õ
```
Due to the nature of the Aheui language, the input must end in a double quotation mark (") (gets ignored).
[Try it here! (copy and paste the code)](http://jinoh.3owl.com/aheui/jsaheui_en.html)
**Bonus (each line is palindromic)**, 131 bytes (42 chars + 5 newlines)
```
Î∞ØÎπ™Î∞òÎ∂ÑÎ∞òÎπ™Î∞Ø
ÏèúÎ∞úÎöùÎ≥ÉÎöùÎ∞úÏèú
ÏèôÌàºÎãøÎóòÎãøÌàºÏèô
ÎΩìÏ≤°ÏàúÍ¥ÜÏàúÏ≤°ÎΩì
ÏàôÏå±Î©àÍ∏ïÎ©àÏå±Ïàô
Î™ãÌù¨ÏùµÏö•ÏùµÌù¨Î™ã
```
[Answer]
# APL -- 13 bytes.
```
‚ä£,¬Ø1‚Üì‚åΩ‚çù‚åΩ‚Üì1¬Ø,‚ä£
```
Explanation:
```
‚ä£,¬Ø1‚Üì‚åΩ
     ‚åΩ Reverse the argument.
  ¬Ø1‚Üì  Drop the last character.
‚ä£,     Concatenate the original to the result.
```
[Answer]
## JavaScript (ES6), ~~86~~ bytes
```
s=>s+[...s].reverse().slice(1).join("")//)""(nioj.)1(ecils.)(esrever.]s...[+s>=s
```
I tried a smarter solution but it's still longer :/ even abusing `[,...a]=s` didn't seem to save bytes
[Answer]
# J, 17 bytes
```
}:,|.NB. .BN.|,:}
```
Takes the easy way out by using a comment to mirror the code. In J, `NB.` starts a line comment. I do hope to find a method that doesn't involve a comment but the digrams in J probably do make it harder.
Also forms two smileys, `}:` and `:}`.
## Usage
```
   f =: }:,|.NB. .BN.|,:}
   f 'abcde'
abcdedcba
```
## Explanation
Comment part removed since it is just filler.
```
}:,|.  Input: string S
   |.  Reverse S
}:     Curtail, get S with its last char removed
  ,    Join them and return
```
[Answer]
# C#, (~~51~~ 50 + 1)\*2 = ~~104~~ 102 bytes
saved 2 bytes to the use of `.Aggregate()`
```
s=>s+s.Aggregate("",(a,b)=>b+a,s=>s.Substring(1));//;))1(gnirtsbuS.s>=s,a+b>=)b,a(,""(etagerggA.s+s>=s
```
You can capture this lambda with
```
Func<string,string> f = <lambda here>
```
and call it like this
```
f("abcde")
```
[Answer]
## Ruby, 47 bytes
```
->s{s+s.reverse[1..-1]}#}[1-..1]esrever.s+s{s>-
```
[Answer]
# Mathematica, 67 bytes
```
f=#~Join~Rest@Reverse@#//Function;noitcnuF//#@esreveR@tseR~nioJ~#=f
```
Defines a named function `f` that takes a list of characters as input and returns the appropriate palindromized list as output. The bit after the semicolon (is fortunately syntactically valid and) gives a second, way more complicated name to this same function.
It was fun trying to make Mathematica make sense without any brackets!
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 11 bytes
```
:Lc.r
r.cL:
```
[Try it online!](http://brachylog.tryitonline.net/#code=OkxjLnIKci5jTDo&input=InRlc3Qi&args=Wg)
### Explanation
```
:Lc.         Input concatenated with a string L results in the Output
   .r(.)     The Output reversed is still the Output
```
The second line is a new predicate declaration that never gets called in that code.
[Answer]
# [Actually](http://github.com/Mego/Seriously), ~~14~~ 13 bytes
```
RiX√üRkŒ£kR√üXiR
```
[Try it online!](http://actually.tryitonline.net/#code=UmlYw59Sa86ja1LDn1hpUg&input=ImFiY2RlIg)
**Explanation**
```
R          # reverse input
 i         # flatten
  X        # discard top of stack
   √üR      # push reversed input
     kŒ£    # concatenate each
k          # wrap in list
 R         # reverse
  √ü        # push input
   X       # discard it
    i      # flatten list to string
     R     # reverse string
```
[Answer]
## Pyke, 1 bytes
```
s
```
[Try it here!](http://pyke.catbus.co.uk/?code=s&input=test)
Yes, this is the same builtin as the digital root one. This time it takes a sting and turns it into a palindrome. Added with [this commit](https://github.com/muddyfish/PYKE/commit/7e79dc95866b451ded61a07cb1da79cf1b1009fb) (actually on the same day as the digital root question)
[Answer]
# Java 7, 146 bytes
(Enter is added for readibility and not part of the code.)
```
String c(String s){return s+new StringBuffer(s).reverse().substring(1);}/
/};)1(gnirtsbus.)(esrever.)s(reffuBgnirtS wen+s nruter{)s gnirtS(c gnirtS
```
[Answer]
# Java 7, 152 bytes
```
String c(char[]s,int i){return s.length==i+1?s[i]+"":s[i]+c(s,++i)+s[i-1];}//};]1-i[s+)i++,s(c+]i[s:""+]i[s?1+i==htgnel.s nruter{)i tni,s][rahc(c gnirtS
```
[Answer]
# PHP, 38+39=77 bytes
```
<?=($s=$argv[1]).substr(strrev($s),1);#;)1,)s$(verrts(rtsbus.)]1[vgra$=s$(=?<
```
stupid restriction ... for non-eso languages :)
[Answer]
# Haskell, ~~46~~ 44 bytes
```
p s=init s++reverse s--s esrever++s tini=s p
```
[Try it on Ideone.](http://ideone.com/VOY2MY) Saved 2 bytes thanks to Damien.
Straight forward solution. `init` takes everything but the last character of a string (or last element of a list). `--` enables a single line comment.
[Answer]
# R, 107 bytes
This is the boring solution which just uses comments to make it a palindrome.
```
cat(x<-scan(,""),rev(strsplit(x,"")[[1]])[-1],sep="")#)""=pes,]1-[)]]1[[)"",x(tilpsrts(ver,)"",(nacs-<x(tac
```
# R with few comments, 271 bytes
While this code is longer, only 89 of the bytes (33%) are comments, rather than the 50% in the above code. R relies extensively on parentheses for function application, so this was rather difficult.
```
`%q%`=function
(x,y)cat(x,y,sep=e)#
`%p%`=function
(x,y)`if`(length(y),rev(y)[-1],x)#
x=strsplit(scan(,e<-""),e)[[1]]#
n=NULL
e%q%x%p%n
n%p%x%q%e
LLUN=n
#]]1[[)e,)""-<e,(nacs(tilpsrts=x
#)x,]1-[)y(ver,)y(htgnel(`fi`)y,x(
noitcnuf=`%p%`
#)e=pes,y,x(tac)y,x(
noitcnuf=`%q%`
```
[Answer]
# WinDbg, ~~142~~ 287 bytes
```
db$t0 L1;.for(r$t1=@$t0;@$p;r$t1=@$t1+1){db$t1 L1};r$t3=@$t1-1;.for(r$t1=@$t1-3;@$t1>=@$t0;r$t1=@$t1-1;r$t3=@$t3+1){m$t1 L1 $t3};eb$t3 0;da$t0;*;0t$ad;0 3t$be;}3t$ 1L 1t$m{)1+3t$@=3t$r;1-1t$@=1t$r;0t$@=>1t$@;3-1t$@=1t$r(rof.;1-1t$@=3t$r;}1L 1t$bd{)1+1t$@=1t$r;p$@;0t$@=1t$r(rof.;1L 0t$bd
```
*+145 bytes to make it a palindrome, nearly missed that requirement...*
Input is passed in via an address in psuedo-register `$t0`. For example:
```
eza 2000000 "abcde"           * Write string "abcde" into memory at 0x02000000
r $t0 = 33554432              * Set $t0 = 0x02000000
* Edit: Something got messed up in my WinDB session, of course r $t0 = 2000000 should work
* not that crazy 33554432.
```
This may be more golfable, for example I feel like there should be an easier way to convert a memory address in a register to the value at that address.
It works by concatenating the chars from the second-to-last to the first to the end of the string.
```
db $t0 L1;                                      * Set $p = memory-at($t0)
.for (r $t1 = @$t0; @$p; r $t1 = @$t1 + 1)      * Set $t1 = $t0 and increment until $p == 0
{
    db $t1 L1                                   * Set $p = memory-at($t1)
};
r $t3 = @$t1 - 1;                               * Point $t3 at end of string
* From the second-to-last char, reverse through the string with $t1 back to the start ($t0)
* and continue to increment $t3 as chars are appended to the string.
.for (r $t1 = @$t1 - 3; @$t1 >= @$t0; r $t1 = @$t1 - 1; r $t3 = @$t3 + 1)
{
    m $t1 L1 $t3                                * Copy char at $t1 to end of string ($t3)
};
eb $t3 0;                                       * Null terminate the new string
da $t0;                                         * Print the palindrome string
* Comment of the previous code in reverse, making the whole thing a palindrome
*;0t$ad;0 3t$be;}3t$ 1L 1t$m{)1+3t$@=3t$r;1-1t$@=1t$r;0t$@=>1t$@;3-1t$@=1t$r(rof.;1-1t$@=3t$r;}1L 1t$bd{)1+1t$@=1t$r;p$@;0t$@=1t$r(rof.;1L 0t$bd
```
Output:
```
0:000> eza 2000000 "abcde"
0:000> r $t0 = 33554432
0:000> db$t0 L1;.for(r$t1=@$t0;@$p;r$t1=@$t1+1){db$t1 L1};r$t3=@$t1-1;.for(r$t1=@$t1-3;@$t1>=@$t0;r$t1=@$t1-1;r$t3=@$t3+1){m$t1 L1 $t3};eb$t3 0;da$t0;*;0t$ad;0 3t$be;}3t$ 1L 1t$m{)1+3t$@=3t$r;1-1t$@=1t$r;0t$@=>1t$@;3-1t$@=1t$r(rof.;1-1t$@=3t$r;}1L 1t$bd{)1+1t$@=1t$r;p$@;0t$@=1t$r(rof.;1L 0t$bd
02000000  61                                               a
02000000  61                                               a
02000001  62                                               b
02000002  63                                               c
02000003  64                                               d
02000004  65                                               e
02000005  00                                               .
02000000  "abcdedcba"
```
[Answer]
# C, 162 bytes
```
f(char*c,char*d){char*e=c;while(*d++=*c++);c-=2;d-=2;do{*d++=*c--;}while(e<=c);}//};)c=<e(elihw};--c*=++d*{od;2=-d;2=-c;)++c*=++d*(elihw;c=e*rahc{)d*rahc,c*rahc(f
```
Ungolfed, unpalindromized:
```
f(char* c,char* d){
 char*e=c;
 while(*d++=*c++);
 c-=2;d-=2;
 do{*d++=*c--;}while(e<=c);
}
```
`c` is is input string, assumes output string `d` has sufficient length.
Usage:
```
int main() {
 char a[] = "abcde";
 char* b=malloc(strlen(a)*2);
 f(a,b);
 printf("%s\n",b);
}
```
[Answer]
# Perl 5, 44 bytes
43 bytes, plus 1 for `-pe` instead of `-e`
```
s#(.*).#$&.reverse$1#e#1$esrever.&$#.)*.(#s
```
[Answer]
# ùîºùïäùïÑùïöùïü, 16 chars / 20 bytes
```
√Ø+√Øƒ¶‚¨Æƒê1//1ƒê‚¨Æƒ¶√Ø+√Ø
```
`[Try it here (ES6 browsers only).](http://molarmanful.github.io/ESMin/interpreter3.html?eval=false&input=asdf&code=%C3%AF%2B%C3%AF%C4%A6%E2%AC%AE%C4%901%2F%2F1%C4%90%E2%AC%AE%C4%A6%C3%AF%2B%C3%AF)`
Generated from the interpreter console using this:
```
c.value=`√Ø+√Ø${alias(String.prototype,'reverse')}‚¨Æ${alias(String.prototype,'slice')}1//1${alias(String.prototype,'slice')}‚¨Æ${alias(String.prototype,'reverse')}√Ø+√Ø`
```
]


[Question]
      [
A string is *pairable* if it can be split into subtrings, each of which is a string repeated twice consecutively. For example, `aabaaababbbaba` is pairable as:
```
aaba aaba
b b
ba ba
```
Given a non-empty string of `a`'s and `b`'s, output a Truthy value if it's pairable and a Falsey value if it isn't.
**Pairable:**
```
aa
abaaba
bbababbb
aabaaababbbaba
babababa
bbbbbbbbbbbb
aaababbabbabbbababbaabaabaababaaba
aaaabaab
```
**Not pairable:**
```
a
ba
baab
abaabaaba
bbbbbbbbbbbbbbb
baababbabaaaab
aaaaabbaaaaa
```
I encourage you to come up with non-regex-based solutions even when there's already a shorter regex answer in your language. You can mark them as "no regex". By regex, I mean a built-in string pattern matching subsystem.
---
**Leaderboard:**
```
var QUESTION_ID=98252,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/98252/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=jQuery(o).text()),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;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;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>
```

[Answer]
# Python 2, ~~68~~ 63 bytes
```
f=lambda s,n=1:s==2*s[:n]or''<s[n:]>-f(s,n+1)<f(s[n:])*f(s[:n])
```
Returns *True* or *False*. Test it on [Ideone](http://ideone.com/WIiCZx).
[Answer]
# [Retina](http://github.com/mbuettner/retina), 11 bytes
```
^((.+)\2)+$
```
[Try all the test cases.](http://retina.tryitonline.net/#code=JWBeKCguKylcMikrJA&input=YWEKYWJhYWJhCmJiYWJhYmJiCmFhYmFhYWJhYmJiYWJhCmJhYmFiYWJhCmJiYmJiYmJiYmJiYgphYWFiYWJiYWJiYWJiYmFiYWJiYWFiYWFiYWFiYWJhYWJhCmEKYmEKYmFhYgphYmFhYmFhYmEKYmJiYmJiYmJiYmJiYmJiCmJhYWJhYmJhYmFhYWFiCmFhYWFhYmJhYWFhYQ) The first two bytes make it multi-line.
Pretty literal interpretation of the rules, obviously uses regex, like all Retina programs will.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ẆŒPẋ€€2F€ċ
```
Not exactly efficient... [Try it online!](http://jelly.tryitonline.net/#code=4bqGxZJQ4bqL4oKs4oKsMkbigqzEiwrhu7TDh-KCrMW84bu0S-KCrFk&input=&args=YWEKYWFiYgphYmFiCmEKYmEKYmFhYgpiYmJiYg)
### How it works
```
ẆŒPẋ€€2F€ċ  Main link. Argument: s (string)
Ẇ           Window, generate the array of all substrings of s.
 ŒP         Powerset; generate all subarrays of substrings of s.
   ẋ€€2     Repeat each substring in each subarray twice.
            For example, ["ab", "a", "b"] becomes ["abab", "aa", "bb"].
       F€   Flatten the subarrays by concatenating their strings.
         ċ  Count how many times s appears in the generated strings.
```
[Answer]
## Haskell, ~~72~~ 69 bytes (no regex)
```
g(a:b:c)|a==b=g c
g x=x==[]
any(g.words.concat).mapM(\c->[[c],c:" "])
```
A brute-force approach. [Try it on Ideone](http://ideone.com/VqybtA).
Thanks to BlackCap for -3 bytes.
## Explanation
The helper function `g` takes a list of strings, and checks that it consists of pairs of identical strings, like `["aa","aa","bba","bba","ab","ab"]`.
The (anonymous) main function splits a string in all possible ways, and checks that at least one splitting results in a list that `g` accepts.
```
g(a:b:c)                                  g on list with elements a, b and tail c,
        |a==b                              in the case that a==b,
             =g c                          recurses to the tail c.
g x=                                      g on any other list x
    x==[]                                  checks that x is empty.
                                           This includes the case where a is not equal
                                           to b, resulting in False.
any(g.words.concat).mapM(\c->[[c],c:" "]) The main function:
                    mapM(\c->[[c],c:" "])  Replace each letter c with either "c" or "c "
                                           in all possible ways, return list of results.
any(              ).                       Check that at least one result satisfies this:
            concat                          Concatenate the 1- or 2-letter strings,
      words.                                split again at each space,
    g.                                      apply g.
```
[Answer]
# Python 2, 60 bytes
```
f=lambda s,t='':''<s>f(s[1:],t+s[0])|f(t and s)*f(t)>-(s==t)
```
I hope this is correct. It runs pretty slowly and the `and` doesn't look optimal.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ŒṖµœs€2ZEµ€S
```
Two bytes longer than [my other answer](https://codegolf.stackexchange.com/a/98259/12012), but this approach is a lot more efficient and handles all but one of the test cases.
[Try it online!](http://jelly.tryitonline.net/#code=xZLhuZbCtcWTc-KCrDJaRcK14oKsUwrhu7ThuaPigJzigJ3Dh-KCrOKCrEc&input=&args=YWEKYWJhYWJhCmJiYWJhYmJiCmFhYmFhYWJhYmJiYWJhCmJhYmFiYWJhCmJiYmJiYmJiYmJiYgoKYQpiYQpiYWFiCmFiYWFiYWFiYQpiYmJiYmJiYmJiYmJiYmIKYmFhYmFiYmFiYWFhYWIKYWFhYWFiYmFhYWFh&debug=on)
### How it works
```
ŒṖµœs€2ZEµ€S  Main link. Argument: s (string)
ŒṖ            Generate all partitions of s.
  µ      µ€   Map the monadic chain between the µ's over the partitions.
   œs€2         Split each string in the partition into two chunks of equal length.
       Z        Zip/transpose, collecting the first halves in one array and the
                second halves in another.
        E       Test the arrays of halves for equality.
           S  Return the sum of the results, counting the number of different
              ways s can be paired.
```
[Answer]
# Pyth - No Regex - ~~13~~ 12 bytes
Checks if any of the partitions are made up of all string that are equals to each other when chopped in two.
```
sm.AqMcL2d./
```
[Test Suite](http://pyth.herokuapp.com/?code=sm.AqMcL2d.%2F&test_suite=1&test_suite_input=%27aa%27%0A%27abaaba%27%0A%27bbababbb%27%0A%27aabaaababbbaba%27%0A%27babababa%27%0A%27bbbbbbbbbbbb%27%0A%27a%27%0A%27ba%27%0A%27baab%27%0A%27abaabaaba%27%0A%27bbbbbbbbbbbbbbb%27%0A%27baababbabaaaab%27%0A%27aaaaabbaaaaa%27&debug=0).
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), 14 bytes (no regex)
```
lye~l:1j@2zcc?
```
[Try it online!](http://brachylog.tryitonline.net/#code=bHllfmw6MWpAMnpjYz8&input=ImFhYmFhYWJhYmJiYWJhIg)
This is too slow for some of the test cases
### Explanation
```
ly                  The list [0, …, length(Input)]
  e~l               A list whose length is an element of the previous list
     :1j            Append itself to this list
        @2zc        Split in half, zip and concatenate so that the list contains pairs of
                      consecutive identical elements
            c?      The concatenation of that list must result in the Input
```
[Answer]
## JavaScript (ES6), no regexp, ~~75~~ 74 bytes
```
f=s=>!s|[...s].some((_,i)=>i&&s[e='slice'](0,i)==s[e](i,i+=i)&&f(s[e](i)))
```
Returns `1` for pairable otherwise `0`. Edit: Saved 1 byte thanks to @edc65.
[Answer]
## Python, 58 bytes
```
f=lambda s,p='':s>''and(f(p)>-(s==p)<f(s))|f(s[1:],p+s[0])
```
This is based on the [Dennis's recursive method](https://codegolf.stackexchange.com/a/98260/20260). The Boolean negation trick is taken from there as well.
The new idea is to recurse over partitions `(p,s)` of the original string by starting with `('',s)` and repeatedly moving the first character of `s` to be the last character of `p`. This allows for the parts to be referred to directly without string slicing. But, because the partition starts with `p` empty, we must be careful to avoid infinite loops of `f(s)` calling `f(s)`.
[Answer]
# JavaScript (ES6), 24 bytes
```
x=>/^((.+)\2)+$/.test(x)
```
Probably doesn't get shorter than this.
[Answer]
# PHP, 40 Bytes
prints 0 for false and 1 for true
```
<?=preg_match("#^((.+)\\2)+$#",$argv[1]);
```
[Answer]
# Python, ~~66~~ 64 bytes
Thanks @Zgarb for -1 byte!
```
f=lambda x,s=1:x>x[:s]and(x==2*x[:s])|f(x[:s])&f(x[s:])|f(x,s+1)
```
Returns `True` or `False`.
[Try it online!](https://repl.it/EQHk/3)
Any help golfing this would be appreciated.
[Answer]
## Racket 230 bytes
```
(let((sl string-length)(ss substring))(if(odd?(sl s))(printf ".~n")(begin(let p((s s))(if(equal? s "")(printf "!")
(for((i(range 1(add1(/(sl s)2)))))(when(equal?(ss s 0 i)(ss s i(* 2 i)))(p(ss s(* 2 i)(sl s)))))))(printf ".~n"))))
```
Prints a '!' for each way in which the string is pairable. Prints a '.' at the end.
Ungolfed:
```
(define (f s)
  (let ((sl string-length)                              ; create short names of built-in fns
        (ss substring))
    (if (odd? (sl s))  (printf ".~n")                   ; odd length strings cannot be pairable; end here.
        (begin
          (let loop ((s s))                             ; start testing here
            (if (equal? s "") (printf "!")              ; if no remaining string, it must be pairable
                (for ((i (range 1 (add1 (/(sl s)2)))))  ; ch lengths varying from 1 to half of string length
                  (when (equal? (ss s 0 i)              ; ch if substrings are same
                                (ss s i (* 2 i)))
                    (loop (ss s (* 2 i) (sl s) ))))))   ; if yes, loop to check remaining string.
          (printf ".~n")))))                            ; End of testing.
```
Testing:
```
(println "Following should be pairable")
(f "bbaabbaa")            ; should produce 2 '!' since 2 ways are possible.
(f "aa")
(f "abaaba")
(f "bbababbb")
(f "aabaaababbbaba")
(f "babababa")                    ; should be pairable in 2 ways.
(f "bbbbbbbbbbbb")                ; should be pairable in many ways.
(f "aaababbabbabbbababbaabaabaababaaba")
(f "aaaabaab")
(println "Following should be unpairable")
; (f "a")
(f "ba")
(f "baab")
(f "abaabaaba")
(f "bbbbbbbbbbbbbbb")
(f "baababbabaaaab")
(f "aaaaabbaaaaa")
```
Output:
```
"Following should be pairable"
!!.
!.
!.
!.
!.
!!.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.
!.
!.
"Following should be unpairable"
.
.
.
.
.
.
```
[Answer]
# Perl, 16 +2 = 18 bytes (with regex)
Run with the `-nl` flags. `-E` is free.
```
say/^((.+)\2)+$/
```
Run as:
```
perl -nlE 'say/^((.+)\2)+$/'
```
Returns a list of the capture groups (a truthy) if pairable, null string if not pairable.
Explanation
The `-nl` flags will run the code in a loop (`-n`), putting the input (with trailing newline removed because of `-l`) into the variable `$_` each time, then evaluating the code each time input is entered, until the program is manually terminated. The `-E` flag lets you evaluate code on the command line, and enables the `say` command.
```
say/^((.+)\2)+$/
   /^((.+)\2)+$/  #The regex engine
      (.+)\2      #Find any set of at least one character, followed by itself
     (      )+    #Do this at least one time
   /^         $/  #Make sure that this matches the entire string from start to end
say               #Output the result of the regex
```
If a match is found (e.g. if the string is pairable), then the regex returns a list of the capture groups, which evaluates to a truthy, which is then passed to `say`, and output. If no match is found, then the regex returns the empty string, which evaluates to falsy, which is then passed to `say`, and output.
Sample:
```
$ perl -nlE 'say/^((.+)\2)+$/'
aaababbabbabbbababbaabaabaababaaba
baababaababaaba                      #Truthy
baababbabaaaab
                                     #Falsy
bbababbb
bbb                                  #Truthy
aabaaababbbaba
bababa                               #Truthy
abaabaaba
                                     #Falsy
```
[Answer]
# GNU Prolog, ~~49~~ 46 bytes
Probably works in other variants too, although they don't all represent strings the same way; GNU Prolog's representation is a useful one for this problem.
It's unclear whether this counts as using regex or not. It's not using any regex-like feature, but the entire semantics of the language are similar to those of regex.
New version (uses the recursion trick seen in some other answers):
```
s(X):-append(A,B,X),(A=B;A\=X,B\=X,s(A),s(B)).
```
Older version:
```
s(X):-X=[];append(A,B,X),B\=X,append(C,C,A),s(B).
```
This is a predicate (Prolog's equivalent of a function) called `s`, not a complete program. Use it like this:
```
| ?- s("aa").
true ?
yes
| ?- s("aaababbabbabbbababbaabaabaababaaba").
true ?
yes
| ?- s("baababbabaaaab").
no
| ?- s("bbbbbbbbbbbbbbb").
no
```
An interesting feature of the older solution is that if you ask the interpreter "are there more solutions?" via use of `;` at the `true ?` prompt (rather than asking "is there any solution" via pressing return at the prompt, like I did above), it returns "true" a number of times equal to the number of different ways the string can be expressed in the given form (e.g. it returns "true" twice with `s("aaaa").`, as this can be parsed as `(a a)(a a)` or as `(aa aa)`).
Prolog programs are often reversible (allowing `s` to *generate* a list of strings with the given property). The older one isn't (it goes into an infinite loop), but that's because of the golfed method I used to ensure that C is nonempty; if you rewrite the program to specify C as nonempty explicitly, it generates strings of the form "aa", "aabb", "aabbcc", and so on (Prolog being Prolog, it doesn't specify identities for the characters that make them up, just a specification of which characters are the same). The newer one generates strings of the form "aa", "abab", "abcabc", and so on; this is an infinite loop in its own right, and thus never hits the point at which it'd get stuck due to failing to detect a zero-length string.
[Answer]
## Brainfuck, 177 bytes
```
+[<<<<,]>>>>[>+[>+[[>>]<+<[<<]>+>-]<[>+<-]>>>,>>[>>]+<<[<+>>-<-]<[>+<-]>>[,>[-<<
<<]<[<<<<]>]<[[<<]>]>>]>>[[>+>>>]>>>[>]<<<<[>+[-<<<,<]<[<<<[[<<<<]>>]<]>]>>]<[[-
>>>>]>>[<]<]<<]<.
```
Formatted:
```
+[<<<<,]
>>>>
[
  >+
  [
    >+
    [
      [>>]
      <+<[<<]
      >+>-
    ]
    <[>+<-]>
    >>,>>[>>]
    +<<[<+> >-<-]
    <[>+<-]>
    >
    [
      not equal
      ,>[-<<<<]
      <[<<<<]
      >
    ]
    <
    [
      equal
      [<<]
      >
    ]
    >>
  ]
  >>
  [
    mismatch
    [>+>>>]
    >>>[>]
    <<<<
    [
      backtrack
      >+[-<<<,<]
      <
      [
        not done yet
        <<<
        [
          [<<<<]
          >>
        ]
        <
      ]
      >
    ]
    >>
  ]
  <
  [
    match
    [->>>>]
    >>[<]
    <
  ]
  <<
]
<.
```
Expects input without a trailing newline. Prints `\x00` for false and `\x01` for true.
[Try it online.](http://brainfuck.tryitonline.net/#code=K1s8PDw8LF0-Pj4-Wz4rWz4rW1s-Pl08KzxbPDxdPis-LV08Wz4rPC1dPj4-LD4-Wz4-XSs8PFs8Kz4-LTwtXTxbPis8LV0-PlssPlstPDw8PF08Wzw8PDxdPl08W1s8PF0-XT4-XT4-W1s-Kz4-Pl0-Pj5bPl08PDw8Wz4rWy08PDwsPF08Wzw8PFtbPDw8PF0-Pl08XT5dPj5dPFtbLT4-Pj5dPj5bPF08XTw8XTwu&input=YmFhYmFhYWE)
This implements depth-first search. In particular: check for repeated prefixes of increasing length starting from the current suffix, then move to the next suffix if a match is found, otherwise backtrack.
At the beginning, the string is reversed and a sentinel `\x01` is placed at the end.
The tape is divided into 4-cell nodes. The memory layout of a node is:
`c h x 0`
where `c` is the character, `h` is a flag for whether the character is in the first half of a repeated prefix, and `x` is a flag to keep track of the current pair of characters being compared. The `h` flags stay in place while the `x` flags form a moving window.
If the string is pairable, the pointer lands next to the sentinel at the end of the main loop; otherwise, the pointer falls off the left side of the string while backtracking.
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 5 bytes
```
~c~jᵐ
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/vy65Luvh1gn//yslJiYlgnBSEhAnKgEA "Brachylog – Try It Online")
Note that this algorithm can take a *very* long time, especially on falsey cases, since it checks every possible partition of the input string.
### Explanation
```
~c     Reversed concatenate: find a list that, when concatenated, results in the input string
       This examines all partitions of the input
  ~jᵐ  Map reversed juxtapose: for each string in that list, is it the result of concatenating
       a string to itself?
```
For an input string like `"ababcc"`, `~c` tries different partitions until it comes to `["abab", "cc"]`, at which point `~j` succeeds for both items of the list, `ᵐ` outputs `["ab", "c"]`, and the predicate succeeds.
[Answer]
# [R](https://www.r-project.org/), 31 bytes
```
grepl("^((.+)\\2)+$",scan(,""))
```
[Try it online!](https://tio.run/##VUzLCoAwDLv3M4qHjQ0Pfs8QUhEvIjL/n7muTrENfSbJpWx5PXfHs3Nj8ClNPgwcrwWHi8zeF4AgqCCRWkWEdIPN7Q7LSviCHobBlECHGaqUdKT38fNQG@k2QCO21haUGw "R – Try It Online")
Based on Retina answer.
# [R](https://www.r-project.org/), 129 bytes
And here’s an original, non-regex answer:
```
o=(y=utf8ToInt(scan(,"")))<0;for(i in 2*1:(sum(y>0)/2))for(j in 1:(i/2)){w=i:(i-j+1);v=w-j;if(all(y[w]==y[v]))o[c(v,w)]=T};all(o)
```
[Try it online!](https://tio.run/##bYnLCsMgFER/JWR1b5vQJKtSe7vvPjtxoQFBSSPkoUjpt1ul2w4MM5yzpuQIIh27vo7uueywTXKBpq4R8d4x7VYwlVmq4dTfYDteEB8dXgbEYmwxmZsC3oFMvq0998g8hdYyo0HOM0QeBFHkXiA6PoFvAgoaP6xIh0kqJUt@o8rk/oPpCw "R – Try It Online")
[Answer]
# [Lithp](https://github.com/andrakis/node-lithp), 57 characters
```
#S::((? (!= (null) (match S "^((.+)\\2)+$")) true false))
```
Sample usage:
```
% pairable_strings.lithp
(
    (def f #S::((? (!= (null) (match S "^((.+)\\2)+$")) true false)))
    (print (f "aa"))
    (print (f "aabaaababbbaba"))
    (print (f "aaababbabbabbbababbaabaabaababaaba"))
    (print (f "ba"))
)
# ./run.js pairable_strings.lithp
AtomValue { value: 2, type: 'Atom', name: 'true' }
AtomValue { value: 2, type: 'Atom', name: 'true' }
AtomValue { value: 2, type: 'Atom', name: 'true' }
AtomValue { value: 3, type: 'Atom', name: 'false' }
```
]