View Category
Fun

produces a copy of its own source code

In computing, a quine is a computer program which produces a copy of its own source code as its only output.
ruby
eval s=%q(puts"eval s=%q(#{s})")
x="x=%p;puts x%%x";puts x%x
java
public class Quine {public static void main(String[] args) {String s = "public class Quine {public static void main(String[] args) {String s = %c%s%c;System.out.printf(s, 34, s, 34);}}";System.out.printf(s, 34, s, 34);}}
public class Quine {
public static void main(String[] args) {
Character cq = (char) 34;
Character cn = (char) 10;
Character cs = (char) 92;
String s = "public class Quine {\n public static void main(String[] args) {\n Character cq = (char) 34;\n Character cn = (char) 10;\n Character cs = (char) 92;\n String s = %c%s%c;\n System.out.printf(s, cq, s.replace(cn.toString(), cs.toString() + 'n'), cq);\n }\n}";
System.out.printf(s, cq, s.replace(cn.toString(), cs.toString() + 'n'), cq);
}
}
perl
seek DATA,0,0;
print <DATA>;
__DATA__
Cheating quine.
$_=q(print qq(\$_=q($_);eval\n));eval
$x=q($x=q(%s);printf($x,$x););printf($x,$x);
groovy
s="s=%s;printf s,s.inspect()";printf s,s.inspect()
evaluate s='char q=39;print"evaluate s=$q$s$q"'
s="s=%c%s%c;printf s,34,s,34";printf s,34,s,34
s='s=%c%s%1$c;printf s,39,s';printf s,39,s
printf _='printf _=%c%s%1$c,39,_',39,_
scala
val s="val s=%c%s%c; printf(s, 34, s, 34)"; printf(s, 34, s, 34)
python
# adapted from a Quine by Sean B. Palmer

print (lambda s='print (lambda s=%r: (s %% s))()': (s % s))()
x='x=%r;print(x%%x)';print(x%x)
cpp
#include <cstdio>
#define B(x) x; printf("{ B(" #x ") }\n");
int main()
{ B(printf("#include <cstdio>\n#define B(x) x; printf(\"{ B(\" #x \") }\\n\");\nint main()\n")) }
fsharp
(fun s -> printf "%s %s" s s) "(fun s -> printf \"%s %s\" s s)"
ocaml
(fun s -> Printf.printf "%s %S" s s) "(fun s -> Printf.printf \"%s %S\" s s)"
(fun p -> Printf.printf p (string_of_format p)) "(fun p -> Printf.printf p (string_of_format p)) %S"
php
// We make sure nothing else is outputted on the screen
ob_end_clean(); // Clean everything
die(highlight_file(__FILE__)); // Print and die
haskell
main = putStr (s ++ [';',' ','s',' ','=',' '] ++ show s); s = "main = putStr (s ++ [';',' ','s',' ','=',' '] ++ show s)
main = (\s -> putStrLn (s ++ show s)) "main = (\\s -> putStrln (s ++ show s)) "
clojure
(def s"(def s%s)(printf s(pr-str s))")(printf s(pr-str s))
fantom
class Q
{
static Void main()
{
r := "class Q\n{\n static Void main()\n {\n r := "
s := "\n s := \n echo (r+r.toCode+s[0..9]+s.toCode+s[10..-1])\n }\n}"
echo (r+r.toCode+s[0..9]+s.toCode+s[10..-1])
}
}
class Q{static Void main(){s:="class Q{static Void main(){s:=;c:=34.toChar;echo(s[0..<30]+c+s+c+s[30..-1]);}}";c:=34.toChar;echo(s[0..<30]+c+s+c+s[30..-1]);}}