Update
This commit is contained in:
parent
e47f0871fe
commit
ac9725b356
38 changed files with 1954 additions and 1872 deletions
8
quine.md
8
quine.md
|
@ -1,12 +1,12 @@
|
|||
# Quine
|
||||
|
||||
Quine is a nonempty [program](program.md) which prints its own source code. It takes no input, just prints out the [source code](source_code.md) when run (without [cheating](cheating.md) such as reading the source code file). Quine is basically a [self-replicating](self_replication.md) program, just as [in real world](irl.md) we may construct robots capable of creating copies of themselves (afterall we humans are such robots). The name *quine* refers to the philosopher Willard Quine and his paradox that shows a structure similar to self-replicating programs. Quine is one of the standard/[fun](fun.md)/[interesting](interesting.md) programs such as [hello world](hello_world.md), [compiler bomb](compiler_bomb.md), [99 bottles of beer](99_bottles.md) or [fizzbuzz](fizzbuzz.md).
|
||||
Quine is a nonempty [program](program.md) that when executed prints its own [source code](source_code.md). It takes no input, just prints out the source code, without "[cheating](cheating.md)" such as reading the source code from a file. A [self-replicating](self_replication.md) program of a sort, quine performs a task similar to that of a robot capable of creating copies of itself (after all we humans are such robots). The name *quine* refers to the philosopher Willard Quine and his paradox that exhibits a structure similar to self-replicating programs. Quine belong to the class of standard/[fun](fun.md)/[interesting](interesting.md) programs with which we like to compare [programming languages](programming_language.md), it's a cousin of such superstars as [hello world](hello_world.md), [compiler bombs](compiler_bomb.md), [99 bottles of beer](99_bottles.md) or [fizzbuzz](fizzbuzz.md), but out of these quine is of the greatest interest to mathematicians.
|
||||
|
||||
From [mathematical](math.md) point of view quine is a fixed point of a [function](function.md) (not to be confused with [fixed_point arithmetic](fixed_point.md)) represented by the [programming language](programming_language.md). I.e. if we see the programming language as a function f(x), where *x* is source code and the function's output is the program's output, quine is such *x* that *f(x) = x*. **A quine can be written in any [Turing complete](turing_completeness.md) [language](programming_language.md)**, the proof comes from the *fixed point theorem* (which says functions satisfying certain conditions always have a fixed point, i.e. a quine).
|
||||
From [mathematical](math.md) viewpoint quine is a **fixed point** of a [function](function.md) (not to be confused with [fixed_point arithmetic](fixed_point.md)) represented by the [programming language](programming_language.md). That is once we say the programming language is a function f(x), where *x* is source code and the function's output is the program's output, quine is such *x* that *f(x) = x*. **A quine can be written in any [Turing complete](turing_completeness.md) [language](programming_language.md)**, the proof comes from the *fixed point theorem* (which says functions satisfying certain conditions always have a fixed point).
|
||||
|
||||
Similar efforts include e.g. making self matching [regular expressions](regex.md) (for this task to be non-trivial the regex has to e.g. be enclosed between `/`s). Yet another similar challenge is a [polyglot](polyglot.md) program -- one that is a valid program in several languages -- some programs can be quines and polyglots at the same time, i.e. **polyglot quines**.
|
||||
Attempt mathematically similar to making quines include e.g. making self matching [regular expressions](regex.md) (for this task to be non-trivial the regex has to be for example enclosed between `/`s). Yet another similar challenge is a [polyglot](polyglot.md) program -- one that is a valid program in several languages -- some programs can be quines and polyglots at the same time, i.e. **polyglot quines**.
|
||||
|
||||
The challenge of creating quines is in the [self reference](self_reference.md) -- normally we cannot just single-line print a string literal containing the source because that string literal would have to contain itself, making it [infinite](infinity.md) in length. The idea commonly used to solve this problem is following:
|
||||
The challenging part of writing quines lies indeed in the [self reference](self_reference.md) -- normally we cannot just single-line print a string literal containing the source because that string literal would have to contain itself, making it [infinite](infinity.md) in length. The idea commonly used to solve the problem is following:
|
||||
|
||||
1. On first line start a definition of string *S*, later copy-paste to it the string on the second line.
|
||||
2. On second line put a command that prints the first line, assigning to *S* the string in *S* itself, and then prints *S* (the second line itself).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue