I came across this term - Quine (also called self-reproducing programs). Just wanted to know more on it. How does one write a quine and are they used anywhere or they are just an exercise for fun?
I've started with Python, and I might try writing one in Python. Any suggestions?
A quine is a fixed point of an execution environment, when the execution environment is viewed as a function transforming programs into their outputs. Quines are possible in any Turing-complete programming language, as a direct consequence of Kleene's recursion theorem.
One of the easiest ways to create a quine is to define a string, then put the string inside itself with string formatting.
Quines are useless in a practical sense, but they're a great exercise to help you learn more about a language.
Here's a very concise one in python:
a='a=%r;print a%%a';print a%a
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With