iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
A quine is a program that prints its own source code when run. It is a small self-reference puzzle—not the same thing as a machine that builds another machine or a worm that copies itself between computers. Those broader examples share the idea of replication, but differ in what gets copied and where the copy goes.
What a quine does
In this article, a quine means a self-contained program whose output is its own source text. It does not read its source file from disk or rely on a special command that displays the program. Those looser techniques can produce the same visible output, but they sidestep the puzzle’s central challenge: generating a representation of the program from within the program itself.
A naive attempt might print a string containing the print statement. But then the output leaves out the statement that prints it. Adding that missing statement to the string creates a new omission, and repeating the fix seems to demand an endlessly nested copy. A quine avoids that regress by dividing the work between a program template and a way to quote that template as valid source text.
Template plus quoted representation
Think of the source as a fixed structure with a slot for a string. One operation emits the structure; another converts the template into a quoted string that can be placed in the slot. The program outputs both pieces in the right order, reconstructing the complete source without embedding an infinite copy inside itself.
#1 Best Overall
Ben Lynn’s Stanford-hosted explanation illustrates this construction in Haskell, where show supplies a string’s quoted representation. The important idea is language-independent: a constructor outputs the program’s structure, while a copier produces a properly escaped representation of the template. Together they emit the original source.
How quines differ from von Neumann machines and worms
“Self-replicating” can describe very different behaviors. To distinguish them, ask what is copied, where the copy goes, and whether the process propagates onto another host.
| Example | What is copied | Where the copy goes | What the example demonstrates |
|---|---|---|---|
| Quine | Source text | The program’s output stream | A program constructs and prints its own source. |
| Von Neumann self-reproducing automaton | A machine description, used to construct a machine | A newly constructed automaton | Construction and copying can be distinct parts of machine reproduction. |
| Worm | A program copy | Another computer | Replication can include movement between hosts. |
These are related ideas, not interchangeable labels. Printing source text does not by itself build a machine or spread a program to another computer.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →What von Neumann’s model adds
John von Neumann considered self-reproducing machines as a broader theoretical problem than the source-code puzzle. In the simplified account in Lynn’s explanation, a universal constructor interprets a description to build a machine, while a separate copying operation duplicates that description. The constructed machine receives the copied description.
Rank #3
This separation matters: a machine need not contain a complete, recursively nested description of itself. Its construction process and the copying of its instructions can work together to produce another machine. Von Neumann’s interest also extended to the possibility of evolution, rather than only to a machine that reproduces an unchanged source string.
His work appeared posthumously in Theory of Self-reproducing Automata, authored by John von Neumann and edited by Arthur Walter Burks. The Google Books bibliographic record lists the volume as published by the University of Illinois Press in 1966 and comprising 388 pages.
Rank #4
What the historical automaton counts mean
A 1966 abstract for Simple self-reproducing universal automata reports that von Neumann and Thatcher had shown that self-reproducing universal arrays could be built with finite automata of 29 states. It then describes a later construction using a basic finite automaton able to execute an internal program of up to 20 instructions. These are figures reported for specific constructions in the article’s abstract, not general counts for quines or all self-reproducing systems.
Why self-copying does not automatically mean malware
Replication alone does not establish malicious intent. IBM’s historical account says Bob Thomas created Creeper in 1971 as an experiment designed to move between ARPANET computers. Ray Tomlinson later modified it so it also copied itself between computers. IBM says Creeper was not malware because it was not intended to damage or disrupt systems. The example shows why movement and copying should be distinguished from the program’s purpose; it does not make every self-copying program a worm or malware.
Best Value
See IBM’s history of computer viruses for that account. Here, Creeper is relevant as a historical example of movement between hosts, not as an example of a quine printing source code.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.How the idea extends beyond source code
A 2018 paper by Chang and Lipson, Neural Network Quine, explored neural networks trained to output their own weights. The authors also considered an auxiliary task: classifying handwritten digits from the MNIST dataset. They report a trade-off between replication and performance on that additional task, and frame the work as a proof of concept.
This is a different kind of self-representation from a source-code quine: the output is a network’s weights, not a printed source file. The paper does not establish that such a network is an autonomous, self-spreading system.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
The core distinction
A quine is the compact programming puzzle: produce your own source as output without inspecting the source file or relying on a self-listing feature. Von Neumann’s automata address machine construction and reproduction through a separate machine description. Worms copy programs between computers. The shared theme is replication; the mechanism, object copied, destination, and purpose determine what each example actually is.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

