g | x | w | all
Bytes Lang Time Link
081AutoHotkey v2241212T091831ZXuesong
038Uiua230930T123831Zlyxal
475Vyxal230927T114219Zlyxal
011Japt230605T233311ZShaggy
132C gcc230603T040413Zlandfill
048Julia 1.0230603T133958ZMarcMush
012Vyxal210519T204902ZAaroneou
027Ruby 0n201222T232410ZDingus
318Java210225T020543ZUnmitiga
046R versiondependent210104T125201ZDominic
011GolfScript140111T053802ZIlmari K
028#PowerShell160112T142157Zbeatcrac
014Japt200629T075756ZMukundan
042Python 3.8 prerelease200128T062120ZMukundan
026Keg200119T233020Zlyxal
041Smalltalk Pharo 2.0 dialect130420T012324Zaka.nice
033Perl 6200119T234730ZJo King
055TeX190909T135546ZSkillmon
054R190909T131018ZRobin Ry
033Zsh190909T102714ZGammaFun
01505AB1E180907T134117ZKevin Cr
068><>160112T141004ZAaron
157Pascal FPC181002T151552ZAlexRace
011Runic180930T030437ZDraco18s
008q180930T021852ZThaufeki
010Jelly180502T185231Zdylnan
014JavaScript ES6180502T181103Zpfg
026Stax180327T043248ZWeijun Z
024><>180323T032000ZJo King
040Python 2180322T220906Ztotallyh
011Husk180129T150047Zბიმო
288Java 8180129T125000ZKevin Cr
187Python150919T003657ZEmilio
019V170714T200742ZDJMcMayh
012CJam170714T195954ZBusiness
047Python 2160514T151442ZRiker
014JavaScript ES6160404T222618ZConor O&
176C140111T011729ZJosh
026GolfScript140110T203951Zaditsu q
038Perl130419T092216Zuser7486
312flex130420T051850ZGeoff Re
026JavaScript130417T171702ZDenys S&
054Node.js130417T174058ZDenys S&
052Perl130417T193527Zmob
035JavaScript V8130418T121353ZGriffin
072Haskell130418T073340Zhammar
133D130418T005949Zratchet
111Tcl130417T151848ZJohannes
055Python 2130417T151448Zflornqua

AutoHotkey (v2), input as arguments, output to MsgBox, 91 93 87 81 bytes

Case insensitive comparison. It's OK since function & var names and strings are all case insensitive

Let it be as strict as possible. Change to a case sensitive comparison.

MsgBox Format(s:='MsgBox Format(s:={:c}{}{1:c},39,s)==A_Args[1]',39,s)==A_Args[1]

It takes command line arguments as input (which need to be double quoted) and outputs in MsgBox.

AutoHotkey (v2), input from stdin1, output to MsgBox, 194 167 122 bytes

MsgBox Format(s:="MsgBox Format(s:={:c}{}{1:c},34,s,10)==FileOpen('*','4').Read(){3:c}",34,s,10)==FileOpen('*','4').Read()

It turns out that when reading from stdin, AHK will add extra new lines, and it has to be removed with Trim. Improved this by open STDIN with mode 4, which converts CR LF to LF. Then append LF to the comparing string.

AutoHotkey (v2), input from stdin, output to stdout1, 212 183 138 bytes

FileAppend Format(s:="FileAppend Format(s:={:c}{}{1:c},34,s,10)==FileOpen('*','4').Read(),'*'{3:c}",34,s,10)==FileOpen('*','4').Read(),'*'

1: AutoHotkey scripts usually run as GUI app on Windows, so stdin/stdout need to be "piped" to/from the program. Also, to literally interpret all quotes as-is, single-quoted "here-strings" must be used as input:

echo @'
input 'string' with "quotes" """ `` '
'@ | autohotkey.exe script.ahk | echo

Uiua, 38 bytes

≅&sc⊂∶!(⊂⊂↷.+1@!)."≅&sc⊂:!(⊂⊂↷.+1@!)."

Explained

≅&sc⊂∶!(⊂⊂↷.+1@!)."≅&sc⊂:!(⊂⊂↷.+1@!)."­⁡​‎‎⁡⁠⁢⁡⁣‏⁠‎⁡⁠⁢⁡⁤‏⁠‎⁡⁠⁢⁢⁡‏⁠‎⁡⁠⁢⁢⁢‏⁠‎⁡⁠⁢⁢⁣‏⁠‎⁡⁠⁢⁢⁤‏⁠‎⁡⁠⁢⁣⁡‏⁠‎⁡⁠⁢⁣⁢‏⁠‎⁡⁠⁢⁣⁣‏⁠‎⁡⁠⁢⁣⁤‏⁠‎⁡⁠⁢⁤⁡‏⁠‎⁡⁠⁢⁤⁢‏⁠‎⁡⁠⁢⁤⁣‏⁠‎⁡⁠⁢⁤⁤‏⁠‎⁡⁠⁣⁡⁡‏⁠‎⁡⁠⁣⁡⁢‏⁠‎⁡⁠⁣⁡⁣‏⁠‎⁡⁠⁣⁡⁤‏⁠‎⁡⁠⁣⁢⁡‏⁠‎⁡⁠⁣⁢⁢‏‏​⁡⁠⁡‌⁢​‎⁠‎⁡⁠⁢⁡⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁣‏⁠‎⁡⁠⁢⁤‏⁠‎⁡⁠⁢⁡⁡‏‏​⁡⁠⁡‌⁤​‎‎⁡⁠⁣⁤‏⁠‎⁡⁠⁤⁡‏⁠‎⁡⁠⁤⁢‏⁠‎⁡⁠⁤⁣‏⁠‎⁡⁠⁤⁤‏‏​⁡⁠⁡‌⁢⁡​‎‎⁡⁠⁣⁢‏⁠‎⁡⁠⁣⁣‏‏​⁡⁠⁡‌⁢⁢​‎‎⁡⁠⁣⁡‏‏​⁡⁠⁡‌⁢⁣​‎‏​⁢⁠⁡‌⁢⁤​‎‎⁡⁠⁢⁡‏⁠‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁣⁡​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌­
                  "≅&sc⊂:!(⊂⊂↷.+1@!)."  # ‎⁡The string "≅&sc⊂:!(⊂⊂↷.+1@!)."
                 .                      # ‎⁢Duplicate it
      !(        )                       # ‎⁣Call the following function on the top copy:
           .+1@!                        # ‎⁤  Push two "
         ⊂↷                             # ‎⁢⁡  Append the first
        ⊂                               # ‎⁢⁢  Prepend the second
# ‎⁢⁣The top of the stack is now a quotified string
    ⊂∶                                  # ‎⁢⁤Prepend the original string without quotes
≅&sc                                    # ‎⁣⁡Does that equal the input?
💎

Created with the help of Luminespire.

Vyxal, 38 bitsv2, 4.75 bytes

`I=`I=

Try it Online!

Explained

`I=`I=­⁡​‎‎⁡⁠⁢⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁡‏⁠‎⁡⁠⁢‏⁠‎⁡⁠⁣‏⁠‎⁡⁠⁤‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌­
     =  # ‎⁡Does the input equal
`I=`    # ‎⁢The string "I="
    I   # ‎⁣With itself wrapped in backticks prepended
💎

Created with the help of Luminespire.

Japt, 11 bytes

¶BîQi"¶BîQi

Try it

¶BîQi"¶BîQi     :Implicit input of string
¶               :Is strictly equal to
 B              :  11
  î             :  Mold to length B
   Q            :    Quotation mark
    i           :    Prepend
     "¶BîQi     :      Literal string

C (gcc), 132 bytes

#define Q(X)main(c,v)int**v;{return!strcmp(#X"\nQ("#X")",v[1]);}
Q(#define Q(X)main(c,v)int**v;{return!strcmp(#X"\nQ("#X")",v[1]);})

Try it online!

It turns out using a macro works out better than using (a)sprintf, even with %c%s%1$c.

I'm not sure if this type of input (a single multiline command-line argument) and output (return value of 1 for true or 0 for false) are allowed.

If they aren't:


C (gcc), 152 bytes

x,y[99];main(z){asprintf(&x,z="x,y[99];main(z){asprintf(&x,z=%c%s%1$c,34,z);gets(y);putchar(48+!strcmp(x,y));}",34,z);gets(y);putchar(48+!strcmp(x,y));}

Try it online!

Assumes an ASCII environment. Reads from stdin, writes 1 or 0 to stdout. Abuses ints as pointers, leaks memory, and uses the dreaded gets :)


In case you're curious, here's the opposite combinations of quine and IO methods:

C (gcc), 136 bytes

x;main(y,v)int**v;{asprintf(&x,y="x;main(y,v)int**v;{asprintf(&x,y=%c%s%1$c,34,y);return!strcmp(x,v[1]);}",34,y);return!strcmp(x,v[1]);}

Try it online!

C (gcc), 158 bytes

#define Q(X)v[40];main(){read(0,v,159);putchar(48+!strcmp(#X"\nQ("#X")",v));}
Q(#define Q(X)v[40];main(){read(0,v,159);putchar(48+!strcmp(#X"\nQ("#X")",v));})

Try it online!

Julia 1.0, 48 bytes

(a=:(show(ARGS[] == "(a=:($(a)))|>eval")))|>eval

Try it online!

Vyxal, 12 bytes

`:q$+=`:q$+=

Try it Online!

I finished making this, and then realized that it is almost identical to the Vyxal quine that @Lyxal wrote, but with the addition of = to check if the input is equal.

Explanation:

              # Implicit input
`:q$+=`       # Push the string ':q$+='
       :      # Duplicate the string
        q     # Quotify; put backticks around the topmost string
         $    # Swap the top two values on the stack
          +   # Concatenate the two strings
           =  # Check if the input is equal to the string
              # Implicit output

Ruby -0n, 32 27 bytes

Saved 5 bytes thanks to a comment by @Sisyphus on another answer.

eval s="p$_=='eval s=%p'%s"

Try it online!

Disclosure: very similar to my answer on a duplicate question.

The -0 flag sets the null byte as the input record separator. Without -0, each line of the input would be read (and tested for equality with the code) separately.

Java, 318 bytes

interface Q{static void main(String[]a){char q=34;String s="interface Q{static void main(String[]a){char q=34;String s=%c%s%c;System.out.print(new java.util.Scanner(System.in).nextLine().equals(String.format(s,q,s,q)));}}";System.out.print(new java.util.Scanner(System.in).nextLine().equals(String.format(s,q,s,q)));}}

Try it online!

R (version-dependent), 46 bytes

f=function(x)x==paste0('f=',capture.output(f))

capture.output - as the function name suggests - retrieves the text string that results from entering the function name f directly to R, which should output the body of the function. We manually prepend this with f= so that it exactly* matches the program code, and check whether the function argument x is the same as this.
*See below

There are a couple of caveats, though, that depend on the R version used:

  1. Early versions of R (like my own version 3.2.1) return the originally-defined function body as-is when the function name is entered to R. However, later versions add additional formatting, like inserting spaces and newlines, which breaks this code: this unfortunately includes the installation (3.5.2) on 'Try it online'. Later still, much newer R versions (I tested 4.0.3) return to the as-is output formatting and everything is Ok again... except...
  2. The most recent versions of R compile functions at the first run, and thereafter append a 'byte code' specific for the compiled function to the outputted function body. This means that capture.output returns two strings, beginning at the second time the function is run. Luckily, the function body is still the first one (the byte code is the second one), so the result of supplying the program code as input is TRUE FALSE, which evaluates to 'truthy' in R and so counts as a 'true' output for this challenge.

Special thanks to Robin Ryder for helping to uncover the version-dependence of R's function outputting.

GolfScript, 11 chars

{`".~"+=}.~

Without the =, this code would be a quine that generates its own source code as a string. The = makes it compare this string to its input and output 1 if they match and 0 if they don't. Note that the comparison is exact — in particular, a trailing newline at the end of the input will cause it to fail.

Explanation:

#PowerShell, 28 bytes

Very similar to this JavaScript answer, uses function provider.

filter f{"$Function:f"-eq$_}

#Example

PS > '"$Function:f"-eq$_' | f
True

PS > 'xxx' | f
False

Japt, 22 16 14 bytes

"iQ ²¶U"iQ ²¶U

Try it online!

Explanation

"iQ ²¶U"iQ ²¶U
"iQ ²¶U"        // Take this string.        iQ ²¶U
        iQ      // Insert a quote.          "iQ ²¶U
           ²    // Double.                  "iQ ²¶U"iQ ²¶U
            ¶U  // Check if equal to input.

Python 3.8 (pre-release), 42 bytes

exec(s:="print('exec(s:=%r)'%s==input())")

Try it online!

Keg, 36 28 26 bytes

`:&\`ⁿ^\`ⁿ&⅀=`:&\`ⁿ^\`ⁿ&⅀=

Try it online!

Same concept as before, but shorter.

Answer History

`:&\`ⁿ⅍^\`ⁿ⅍++&+¿=`:&\`ⁿ⅍^\`ⁿ⅍++&+¿=

Try it online!

Who knew generating a program that knows itself would be so unreadable!

Explained

The very first step here is to generate the string that will be checked against. At this point, we don't particularly know what the checking part will look like, but we do know that there will be a string that looks like so:

`\`ⁿ⅍^\`ⁿ⅍++`

Which would consequently be followed by:

 \`ⁿ⅍^\`ⁿ⅍++

This creates a string which contains itself quoted... Something needed for when input is taken, as the quotes are going to be present.

From here, string equality is quite easy, coming in at a trivial 2 bytes:

¿=

Incorporating this into the string gives:

`\`ⁿ⅍^\`ⁿ⅍++¿=`\`ⁿ⅍^\`ⁿ⅍++¿=

At this stage, one might think the quine is complete... It has the string part and it has the equality part... What else could be needed? Well. Let me tell you we ain't done yet.

Y'see, we have a quoted string on the stack, but we don't have it's unquoted equivalent present, meaning we need to account for that. The register works well here:

`:&\`ⁿ⅍^\`ⁿ⅍++&+¿=`:&\`ⁿ⅍^\`ⁿ⅍++&+¿=

And there you have it: a self identifying program written completely on a phone keyboard.

Smalltalk (Pharo 2.0 dialect), 41 bytes

Implement this 41 chars method in String (ugly formatting for code-golf):

isItMe^self=thisContext method sourceCode

Then evaluate this in a Workspace (printIt the traditional Smalltalk way)
The input is not read from stdin, it's just a String to which we send the message (what else a program could be in Smalltalk?):

'isItMe^self=thisContext method sourceCode' isItMe.

But we are cheating, sourceCode reads some source file...
Here is a variant with 51 chars which does not:

isItMe
    ^ self = thisContext method decompileString

And test with:

'isItMe
    ^ self = thisContext method decompileString' isItMe

If a String in a Workspace is not considered a valid input, then let's see how to use some Dialog Box in 116 chars
Just evaluate this sentence:

(UIManager default request: 'type me') = (thisContext method decompileString withSeparatorsCompacted allButFirst: 7)

Since decompile format includes CR and TAB, we change that withSeparatorsCompacted.
Then we skip the first 7 chars are 'doIt ^ '

Finally a 105 chars variant using stdin, just interpret this sentence from command line, just to feel more mainstream:

Pharo -headless Pharo-2.0.image eval "FileStream stdin nextLine = (thisContext method decompileString withSeparatorsCompacted allButFirst: 7)"

Perl 6, 33 bytes

<dd "<$_>~~.EVAL"eq slurp>~~.EVAL

Try it online!

Outputs either Bool::True or Bool::False to STDERR. This is the basic quine format, with an added check against input (eq slurp).

TeX, 55 bytes

The file has to be saved as a.tex and should be run using pdftex a.tex. The script doesn't terminate after returning 1 or 0, if that should be necessary append it by \end (+4 bytes). If it should work for arbitrary file names replace \openin0a with \openin0\jobname (+7 bytes).

\openin0=a\read0to\0\read1to~\message{\ifx\0~1\else0\fi}

R, 54 bytes

f=function(s)s==paste0("f=function(s)s==", body(f)[3])

Try it online!

body gets the body of the function (splitting it a bit, so that body(f)[3] is everything from paste0 onwards). Interestingly, body reformats the code, adding spaces after commas, etc. This is thus a rare case of an R golf answer with a space after a comma.

This works because body(f) is an object of type language, and there exists an as.character method for this type. On the other hand, f and args(f) are of type closure, and cannot be converted to character type as far as I can tell. Please don't ask me what the language type is for…

Zsh, 33 bytes

f () {
	[ "`type -f f`" = $1 ]
}

Try it online!

The extra spaces, tab, and newlines are required. type -f f does not print the original source, but the function formatted in a particular way, with indentation and a trailing newline.

05AB1E, 15 bytes

0"D34çýQ"D34çýQ

Modifies the default 0"D34çý"D34çý by adding Q (check for equality with the implicit input)

Try it online.

Explanation:

0                # Push 0 to the stack
                 #  STACK: [0]
 "D34çýQ"        # Push the string 'D34çýQ' to the stack
                 #  STACK: [0, 'D34çýIå']
         D       # Duplicate this string
                 #  STACK: [0, 'D34çýIå', 'D34çýIå']
          34ç    # Push '"' to the stack
                 #  STACK: [0, 'D34çýIå', 'D34çýIå', '"']
             ý   # Join the stack by this '"' delimiter
                 #  STACK: ['0"D34çýIå"D34çýIå']
              Q  # Check if it's equal to the (implicit) input
                 # (and output the top of the stack implicitly as result)

Cool 15 bytes alternative provided by @Grimy:

187745012D27BJQ

Try it online.

Explanation:

187745012        # Push integer 187745012 
                 #  STACK: [187745012]
         D       # Duplicate it
                 #  STACK: [187745012, 187745012]
          27     # Push integer 27
                 #  STACK: [187745012, 187745012, 27]
            B    # Convert 187745012 to base-27
                 #  STACK: [187745012, "D27BJQ"]
             J   # Join the values on the stack together
                 #  STACK: ["187745012D27BJQ"]
              Q  # Check if it's equal to the (implicit) input
                 # (and output the top of the stack implicitly as result)

><>, 68 bytes

Fishes love eating fish poop. Now we know they can distinguish theirs from their friends'.

00v      0+1~$^?)0~\;n0\
  >:@@:@gi:0(?\:a=?/=?!/$1+
  0n;n*=f$=2~~/

You can try it online !

Pascal (FPC), 167 157 bytes

const b=#39';var s:string;begin read(s);write(s=a+b+#39#59#97#61#39+a+b)end.';a='const b=#39';var s:string;begin read(s);write(s=a+b+#39#59#97#61#39+a+b)end.

Try it online!

While substring can be easily extracted, like in my regular quine, unfortunately, they cannot be concatenated because FPC thinks it is an array in these circumstances. In a and b are characters before and after constant definitions. #39#59#97#61#39 is a replacement for ';a=' as this is not represented in the constants. #39 represents ' and is at the start of b, glued together to the rest of b, to shorten the comparison expression as much as possible.

Runic, 11 bytes

"3X4+kSqi=@

Try it online!

TIO got updated and there's no longer an issue reading input (and no longer requires a trailing whitespace).

Explanation

>                 Implicit entry
 "                Begin reading as string
  3X4+kSqi=@      Pushed to the stack as a string, loop around
 "                End reading as string
  3X4+            Push 3*10 and 4 to the stack, add them together
      k           Convert to character (")
       S          Swap the top two items on the stack
        q         Concatenate. This leaves only "3X4+kSqi=@ on the stack
         i        Read input
          =       Compare using .Equals, push 1 if equal, else 0
           @      Print and terminate

JoKing's solution:

"'<~qi=@|

Explanation

  <              Entry
 '               Read character (loop around)
"                Push "
         |       Mirror
"                Begin reading string (loop around)
 '<~ri=@|        Push the string '<~qi=@| (loop around)
"                End reading string
 '<~             Push the character < and then discard it
    q            Concatenate, stack contains only "'<~qi=@|
      i          Read input
       =         Compare
        @        Print and terminate

q, 8 bytes

{x~.z.s}

Return boolean on input matching the self-referential .z.s

Jelly, 10 bytes

“Ṿ;$⁼”Ṿ;$⁼

Try it online!

“Ṿ;$⁼”Ṿ;$⁼
“Ṿ;$⁼”      String literal: 'Ṿ;$⁼'
        $   Next two links act on the string literal
      Ṿ     Uneval: '“Ṿ;$⁼”'
       ;    Append string: '“Ṿ;$⁼”Ṿ;$⁼' (source code)
         ⁼  Is the string above equal to the input?

JavaScript ES6, 14 bytes

Like the other javascript answer but includes it's entire source code and not just the function

a=q=>'a='+a==q

Example usage:

a("q=>'a='+a==q") // returns false
a("a=q=>'a='+a==q") // returns true

Stax, 26 bytes

"34bLN26)s:f="34bLN26)s:f=

Run and debug it

><>, 24 bytes

'1rd3*i={*}50l3-?.~i)*n;

Try it online!

Wrapping string literal followed by checking whether the input is identical to the stack, with a final check that there is no more input.

Python 2, 40 bytes

s="print's=%r;exec s'%s==input()";exec s

Try it online!

Husk, 11 bytes

=hS+s"=hS+s

Try it online!

Explanation

The explanation uses ¨ to delimit strings (to avoid unreadable escaping):

     "=hS+s  -- string literal: ¨=hS+s¨
  S+         -- join itself with
    s        -- | itself "showed": ¨"=hS+s"¨
             -- : ¨=hS+s"=hS+s"¨
 h           -- init: ¨=hS+s"=hS+s¨
=            -- is the input equal?

By removing the function = you can verify that it will indeed only match the source itself.

Java 8, 288 bytes (Full Program with STDIN)

interface M{static void main(String[]a){String s="interface M{static void main(String[]a){String s=%c%s%1$c;System.out.print(s.format(s,34,s).equals(new java.util.Scanner(System.in).nextLine()));}}";System.out.print(s.format(s,34,s).equals(new java.util.Scanner(System.in).nextLine()));}}

Try it online.

Java 8, 210 bytes (Full Program with Console Arguments)

interface M{static void main(String[]a){String s="interface M{static void main(String[]a){String s=%c%s%1$c;System.out.print(s.format(s,34,s).equals(a[0]));}}";System.out.print(s.format(s,34,s).equals(a[0]));}}

Try it online.

Java 8, 108 bytes (Function)

i->{String s="i->{String s=%c%s%1$c;return s.format(s,34,s).equals(i);}";return s.format(s,34,s).equals(i);}

Try it online.

Explanation:

-part:

Challenge-part:

Python, 187 bytes

import sys;code="import sys;code=!X!;print(sys.stdin.read()==code.replace(chr(33),chr(34)).replace(!X!,code,1))";print(sys.stdin.read()==code.replace(chr(33),chr(34)).replace("X",code,1))

Careful not to add newline at the end. Someone with better Python-fu might be able to shorten it.

V, 19 bytes

ñOÑ~"qpxØ¥^¨©î±¥$

Try it online!

Prints 1 or 0. Here is a hexdump:

00000000: f14f d11b 7e22 7170 78d8 a55e a881 a9ee  .O..~"qpx..^....
00000010: b1a5 24                                  ..$

CJam, 12 bytes

{s"_~"+q=}_~

Try it online!

Explanation

This just uses the standard CJam quine framework.

{s"_~"+q=}    e# Push this block (function literal).
          _~  e# Copy and run it.

What the block does:

 s            e# Stringify the top element (this block itself).
  "_~"+       e# Append "_~". Now the source code is on the stack.
       q      e# Read the input.
        =     e# Check if it equals the source code.

Python 2, 47 bytes

_='_=%r;print _%%_==input()';print _%_==input()

A simple quine with the added check.

JavaScript ES6, 16 14 bytes

$=_=>_==`$=`+$

Minus two bytes thanks to Neil.

31 bytes if we must take input via prompt.

$=_=>prompt()==`$=${$};$()`;$()

38 bytes if we must output via alert.

$=_=>alert(prompt()==`$=${$};$()`);$()

This is the proper way to do it, as Optimizer's answer does not accept the entire source code.

C - 186 176 characters

One liner:

 *a="*a=%c%s%c,b[999],c[999];main(){sprintf(b,a,34,a,34);gets(c);putchar(strcmp(b,c)?'0':'1');}",b[999],c[999];main(){sprintf(b,a,34,a,34);gets(c);putchar(strcmp(b,c)?'0':'1');}

With whitespace (note that this breaks the program):

*a="*a=%c%s%c,b[999],c[999];main(){sprintf(b,a,34,a,34);gets(c);putchar(strcmp(b,c)?'0':'1');}",b[999],c[999];
main() {
  sprintf(b,a,34,a,34);
  gets(c);
  putchar(strcmp(b,c)?'0':'1');
}

GolfScript - 26

":@;[34]@+2*=":@;[34]@+2*=

Inspired from http://esolangs.org/wiki/GolfScript#Examples

Another version:

"[34].@@;+2*="[34].@@;+2*=

Too bad that \ is both swap and escape...

Perl, Infinity 41 38 Characters

$_=q(print<>eq"\$_=q($_);eval"|0);eval

Update: The program no longer ends with a newline, which means it will work correctly on multi-line files. You have to enter input from STDIN without hitting enter. On Windows I was only able to do this by reading from a file.

Original solution:

print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(print<>==q(...

flex - 312 chars

Q \"
N \n
S " "
B \\
P "Q{S}{B}{Q}{N}N{S}{B}n{N}S{S}{Q}{S}{Q}{N}B{S}{B}{B}{N}P{S}{Q}{P}{Q}{N}M{S}{Q}{M}{Q}{N}%%{N}{P}{N}{M}{N} putchar('1');"
M "(.|{N})* putchar('0');"
%%
Q{S}{B}{Q}{N}N{S}{B}n{N}S{S}{Q}{S}{Q}{N}B{S}{B}{B}{N}P{S}{Q}{P}{Q}{N}M{S}{Q}{M}{Q}{N}%%{N}{P}{N}{M}{N} putchar('1');
(.|{N})* putchar('0');

Can probably be made shorter, but it works with multi-line input (necessary since the source code is multiple lines) and even for inputs that contain the program as a substring. It seems many of the answers so far fail on one or both of these.

Compile command: flex id.l && gcc -lfl lex.yy.c

JavaScript : 26

function f(s){return s==f}

I don't know if a JavaScript file really qualifies as a "program".

Node.js : 54

function f(){console.log(f+'f()'==process.argv[2])}f()

You test it by saving it into a file f.js (the exact name has no importance) and using

node f.js "test"

(which outputs false) or

node f.js "$(< f.js)"

(which outputs true)

I also made a different version based on eval :

eval(f="console.log('eval(f='+JSON.stringify(f)+')'==process.argv[2])")

It's now at 72 chars, I'll try to shorten that when I have time.

Perl, 52 char

$_='$/=$\;$_="\$_=\47$_\47;eval";print<>eq$_|0';eval

JavaScript (V8), 35

function i(){alert(prompt()==i+[])}

call i() and it will prompt for input

Haskell, 72 characters

main=interact$show.(==s++show s);s="main=interact$show.(==s++show s);s="

Note: there is no end-of-line character at the end of the script.

$ runhaskell Self.hs < Self.hs
True

D (133 chars)

enum c=q{import std.stdio;import std.algorithm;void main(){auto i=readln();writeln(equal("auto c=q{"~c~"};mixin(c);",i));}};mixin(c);

Tcl, 111 chars

set c {set c {$c};puts [expr {[read stdin] eq [subst -noc \$c]}]};puts [expr {[read stdin] eq [subst -noc $c]}]

Python 2, 55

a='a=%r;print a%%a==raw_input()';print a%a==raw_input()

Tested:

a='a=%r;print a%%a==raw_input()';print a%a==raw_input() -> True

(anything else) -> False