# Write a self-aware program [duplicate]

A standard (but disputed) test of self-awareness is the mirror test: An animal is considered self aware if it can recognize itself in the mirror.

Your task is to write a program that is self-aware according to this test. More exactly:

• The program reads input in whatever form is suitable for your language.

• If the input contains a mirror image of its own source code, it produces a truthy value, otherwise a falsey value.

• A valid mirror image is the exact source of the program with the order of characters reversed, with no extra characters in between. As a special exception, for systems/languages that don't use single characters to terminate/separate lines (e.g. using a CR/LF sequence), the line termination sequence is allowed, but not required to be kept intact on reversal. However the program must be consistent in its treatment of lines.

For example, on a system using CR/LF as line separator, the sequence AB<cr><lf>CD may be reversed either to DC<cr><lf>BA (keeping the line ending intact) or to DC<lf><cr>BA (completely reversing the character sequence).

• The mirror image must be detected also if it is preceded or followed by junk, even if that junk contains reversed fragments of the code.

This is code golf; the shortest entry wins.

Note this is not the same as this question because of (a) the reversal of the code, and (b) the fact that it has to tolerate junk before and after the reversed code, including junk that is very similar to the actual reversed code.

• Borderline duplicate. – Martin Ender Oct 15 '16 at 21:50
• @MartinEnder I'd call it a dupe. – xnor Oct 15 '16 at 21:51
• Note about generalized quines. – xnor Oct 15 '16 at 21:54
• @xnor I was just about to post that before I realised that Retina does actually have a solution that isn't based on the standard quine. – Martin Ender Oct 15 '16 at 21:56
• Please use the Sandbox in the future to get feedback on your challenges before posting them to the main site. – user45941 Oct 15 '16 at 21:57

## Retina, 1 byte

x


Try it online!

Prints a positive integer when the input contains at least one "reversed" copy of the source and 0 otherwise.

Any character that isn't a backtick or a regex metacharacter ([()?*+\\^\$.) would work.

• Interesting solution, but don't we require quines to be proper now? – xnor Oct 15 '16 at 21:58
• @xnor If we extend that definition to generalised quines, then don't all solutions have to be extensions of a standard quine? I figured the only way to have interesting solutions to those is to find a way to circumvent that. (Especially since there's no way to use this approach for a standard quine in Retina, nor for most generalised quines.) – Martin Ender Oct 15 '16 at 22:00