This commit is contained in:
Miloslav Ciz 2023-06-02 22:57:53 +02:00
parent 08f5a7c291
commit 3feba5f984
7 changed files with 29 additions and 15 deletions

View file

@ -2,7 +2,7 @@
Quine is a nonempty [program](program.md) which prints its own source code. It takes no input, just prints out the source code when run (without [cheating](cheating.md) such as reading the source code file). Quine is basically a self-replicating 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), [99 bottles of beer](99_bottles.md) or [fizzbuzz](fizzbuzz.md).
Quine can be written in any [Turing complete](turing_completeness.md) [language](programming_language.md), the challenge 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:
Quine can be written in any [Turing complete](turing_completeness.md) [language](programming_language.md) (according to [Wikipedia](wikipedia.md)), the challenge 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:
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).
@ -22,6 +22,14 @@ s="print(str().join([chr(115),chr(61),chr(34)]) + s + str().join([chr(34),chr(10
print(str().join([chr(115),chr(61),chr(34)]) + s + str().join([chr(34),chr(10)]) + s)
```
This is a quine in [comun](comun.md):
```
0 46 32 34 S 34 32 58 83 S --> S: "0 46 32 34 S 34 32 58 83 S --> " .
```
TODO: more langs?
In the [Text](plaintext.md) [esoteric programming language](esolang.md) every program is a quine.
Yet a stronger quine is so called *radiation hardened quine*, a quine that remains quine even after any one character from the program has been deleted (found here in [Ruby](ruby.md): https://github.com/mame/radiation-hardened-quine).
In the [Text](plaintext.md) [esoteric programming language](esolang.md) every program is a quine (and so also a radiation hardened one).