850 captures
13 Sep 2006 - 30 Jan 2026
May JUN Jul
21
2012 2013 2014
success
fail

About this capture

COLLECTED BY

Organization: Internet Archive

The Internet Archive discovers and captures web pages through many different web crawls. At any given time several distinct crawls are running, some for months, and some every day or longer. View the web archive through the Wayback Machine.

Collection: Wide Crawl started April 2013

Web wide crawl with initial seedlist and crawler configuration from April 2013.
TIMESTAMPS

The Wayback Machine - http://web.archive.org/web/20130621170937/http://en.wikipedia.org/wiki/Quine_(computing)
 



Quine (computing)



From Wikipedia, the free encyclopedia


Jump to: navigation, search  
A quine's output is exactly the same as its source code.

Aquine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are self-replicating programs, self-reproducing programs, and self-copying programs.

A quine is a fixed point of an execution environment, when the execution environment is viewed as a function. Quines are possible in any programming language that has the ability to output any computable string, as a direct consequence of Kleene's recursion theorem. For amusement, programmers sometimes attempt to develop the shortest possible quine in any given programming language.

The name "quine" was coined by Douglas Hofstadter, in his popular science book Gödel, Escher, Bach: An Eternal Golden Braid, in the honor of philosopher Willard Van Orman Quine (1908–2000), who made an extensive study of indirect self-reference, and in particular for the following paradox-producing expression, known as Quine's paradox:

"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.

In some languages, an empty source file is a fixed point of the language, producing no output. Such an empty program, submitted as "the world's smallest self reproducing program", once won the "worst abuse of the rules" prize in the International Obfuscated C Code Contest.[1]

Contents

History[edit]

The idea of self-reproducing programs first appeared in Paul Bratley and Jean Millo's article "Computer Recreations: Self-Reproducing Automata" in 1972.[2] Bratley first became interested in self-reproducing programs after seeing the first known such program written in Atlas Autocode at Edinburgh in the 1960s by the University of Edinburgh lecturer and researcher Hamish Dewar. This program appears below:

%BEGIN
!THIS IS A SELF-REPRODUCING PROGRAM
%ROUTINESPEC R
R
PRINT SYMBOL(39)
R
PRINT SYMBOL(39)
NEWLINE
%CAPTION %END~
%CAPTION %ENDOFPROGRAM~
%ROUTINE R
%PRINTTEXT '
%BEGIN
!THIS IS A SELF-REPRODUCING PROGRAM
%ROUTINESPEC R
R
PRINT SYMBOL(39)
R
PRINT SYMBOL(39)
NEWLINE
%CAPTION %END~
%CAPTION %ENDOFPROGRAM~
%ROUTINE R
%PRINTTEXT '
%END
%ENDOFPROGRAM

Example[edit]

The following Java code demonstrates the basic structure of a quine.

public class Quine
{
  public static void main( String[] args )
  {
    charq= 34;      // Quotation mark character
    String[]l= {    // Array of source code
    "public class Quine",
    "{",
    "  public static void main( String[] args )",
    "  {",
    "    char q = 34;      // Quotation mark character",
    "    String[] l = {    // Array of source code",
    "    ",
    "    };",
    "    for( int i = 0; i < 6; i++ )           // Print opening code",
    "        System.out.println( l[i] );",
    "    for( int i = 0; i < l.length; i++ )    // Print string array",
    "        System.out.println( l[6] + q + l[i] + q + ',' );",
    "    for( int i = 7; i < l.length; i++ )    // Print this code",
    "        System.out.println( l[i] );",
    "  }",
    "}",
    };
    for( inti= 0;i< 6;i++ )           // Print opening code
        System.out.println(l[i] );
    for( inti= 0;i< l.length;i++ )    // Print string array
        System.out.println(l[6] +q+l[i] +q+ ',' );
    for( inti= 7;i< l.length;i++ )    // Print this code
        System.out.println(l[i] );
  }
}

The source code contains a string array of itself, which is output twice, once inside quotation marks.

A very concise quine with the same basic structure can be written in Lua:

x= [["x = [" .. "[" .. x .. "]" .. "]\nprint(" .. x)]]
print("x = [" .. "[" ..x.. "]" .. "]\nprint(" ..x)

Quines can take advantage of eval. For example, this Ruby quine:

eval s="print 'eval s=';p s"

However quines cannot receive any form of input, including reading a file, which means the following shell script is not a quine.

# Invalid quine. 
# Reading the executed file from disk is cheating
cat $0

Multiquines[edit]

The quine concept can be extended to multiple levels or recursion, originating what has been called[by whom?] multiquines, or "ouroboros programs".

Example[edit]

This Java program outputs the source for a C++ program that outputs the original Java code.

#include <iostream>
#include <string>
using namespace std;
 
int main(int argc, char* argv[])
{
    charq= 34;
    string l[] = {
    "    ",
    "=============<<<<<<<< C++ Code >>>>>>>>=============",
    "#include <iostream>",
    "#include <string>",
    "using namespace std;",
    "",
    "int main(int argc, char* argv[])",
    "{",
    "    char q = 34;",
    "    string l[] = {",
    "    };",
    "    for( int i = 20; i <= 25; i++ )",
    "        cout << l[i] << endl;",
    "    for( int i = 0; i <= 34; i++ )",
    "        cout << l[0] + q + l[i] + q + ',' << endl;",
    "    for( int i = 26; i <= 34; i++ )",
    "        cout << l[i] << endl;",
    "    return 0;",
    "}",
    "=============<<<<<<<< Java Code >>>>>>>>=============",
    "public class Quine",
    "{",
    "  public static void main( String[] args )",
    "  {",
    "    char q = 34;",
    "    String[] l = {",
    "    };",
    "    for( int i = 2; i <= 9; i++ )",
    "        System.out.println( l[i] );",
    "    for( int i = 0; i < l.length; i++ )",
    "        System.out.println( l[0] + q + l[i] + q + ',' );",
    "    for( int i = 10; i <= 18; i++ )",
    "        System.out.println( l[i] );",
    "  }",
    "}",
    };
    for( inti= 20;i<= 25;i++ )
        cout <<l[i] << endl;
    for( inti= 0;i<= 34;i++ )
        cout <<l[0] +q+l[i] +q+ ',' << endl;
    for( inti= 26;i<= 34;i++ )
        cout <<l[i] << endl;
    return 0;
}
public class Quine
{
  public static void main( String[] args )
  {
    charq= 34;
    String[]l= {
    "    ",
    "=============<<<<<<<< C++ Code >>>>>>>>=============",
    "#include <iostream>",
    "#include <string>",
    "using namespace std;",
    "",
    "int main(int argc, char* argv[])",
    "{",
    "    char q = 34;",
    "    string l[] = {",
    "    };",
    "    for( int i = 20; i <= 25; i++ )",
    "        cout << l[i] << endl;",
    "    for( int i = 0; i <= 34; i++ )",
    "        cout << l[0] + q + l[i] + q + ',' << endl;",
    "    for( int i = 26; i <= 34; i++ )",
    "        cout << l[i] << endl;",
    "    return 0;",
    "}",
    "=============<<<<<<<< Java Code >>>>>>>>==========",
    "public class Quine",
    "{",
    "  public static void main( String[] args )",
    "  {",
    "    char q = 34;",
    "    String[] l = {",
    "    };",
    "    for( int i = 2; i <= 9; i++ )",
    "        System.out.println( l[i] );",
    "    for( int i = 0; i < l.length; i++ )",
    "        System.out.println( l[0] + q + l[i] + q + ',' );
    ",
    "    for( int i = 10; i <= 18; i++ )",
    "        System.out.println( l[i] );",
    "  }",
    "}",
    };
    for( inti= 2;i<= 9;i++ )
        System.out.println(l[i] );
    for( inti= 0;i< l.length;i++ )
        System.out.println(l[0] +q+l[i] +q+ ',' );
    for( inti= 10;i<= 18;i++ )
        System.out.println(l[i] );
 
 }
}

Such programs have been produced with various cycle lengths:

See also[edit]

References[edit]

  1. ^ IOCCC 1994 Worst Abuse of the Rules
  • ^ Bratley, Paul; Millo, Jean (1972). "Computer Recreations: Self-Reproducing Automata". Software Practice and Experience 2: 397–400. 
  • ^ Dan Piponi (5 February 2008). "A Third Order Quine in Three Languages". 
  • ^ Bruce Ediger. "Ask and ye shall receive: Self-replicating program that goes through three generations, Python, Bash, Perl". 
  • ^ b.m. (1 February 2011). "multiquine". 
  • ^ Dan Piponi (30 January 2011). "Quine Central". 
  • ^ Ruslan Ibragimov (20 April 2013). "Chaine Quine". 
  • ^ Shinichiro Hamaji (10 November 2007). "Quine by shinh (C C++ Ruby Python PHP Perl)".  (this one is also a polyglot)
  • ^ Ku-ma-me (22 September 2009). "Uroboros Programming With 11 Programming Languages". 
  • Further reading[edit]

    External links[edit]

    Retrieved from "http://en.wikipedia.org/w/index.php?title=Quine_(computing)&oldid=560159772" 

    Categories: 
    Source code
    Willard Van Orman Quine
    Test items
    Hidden categories: 
    Articles with specifically marked weasel-worded phrases from April 2013
    Articles with example C code




    Navigation menu



    Personal tools



    Create account
    Log in
     



    Namespaces



    Article

    Talk
     


    Variants









    Views



    Read

    Edit

    View history
     


    Actions













    Navigation




    Main page

    Contents

    Featured content

    Current events

    Random article

    Donate to Wikipedia
     



    Interaction




    Help

    About Wikipedia

    Community portal

    Recent changes

    Contact Wikipedia
     



    Toolbox




    What links here

    Related changes

    Upload file

    Special pages

    Permanent link

    Page information

    Cite this page
     



    Print/export




    Create a book

    Download as PDF

    Printable version
     



    Languages




    Беларуская (тарашкевіца)

    Български

    Česky

    Dansk

    Deutsch

    Español

    Français



    Italiano



    Polski

    Português

    Русский

    Simple English

    Suomi

    Svenska



    Edit links
     







    This page was last modified on 16 June 2013 at 14:57.

    Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. 
    Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.
     


    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Mobile view
     


    Wikimedia Foundation
    Powered by MediaWiki