Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are quines? Any specific purpose to have them? [closed]

Tags:

python

quine

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?

like image 995
Arnkrishn Avatar asked Jul 10 '09 20:07

Arnkrishn


People also ask

What is the purpose of a quine?

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.

How do you make a quine?

One of the easiest ways to create a quine is to define a string, then put the string inside itself with string formatting.


1 Answers

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
like image 101
Algorias Avatar answered Sep 28 '22 14:09

Algorias