Questions tagged [quine]

A program that generates a copy of its own source text as its complete output (generally of interest in theory only).

A program that generates a copy of its own source text as its complete output. This is generally considered of interest in theory only; but highly self-contained programs ( for example) may be viewed as quine-like. Named after the logician Willard van Orman Quine

99 questions
46
votes
11 answers

Shortest Python Quine?

Python 2.x (30 bytes): _='_=%r;print _%%_';print _%_ Python 3.x (32 bytes) _='_=%r;print(_%%_)';print(_%_) Is this the shortest possible Python quine, or can it be done better? This one seems to improve on all the entries on The Quine…
wim
  • 338,267
  • 99
  • 616
  • 750
34
votes
4 answers

Is it possible to create a quine in every turing-complete language?

I just wanted to know if it is 100% possible, if my language is turing-complete, to write a program in it that prints itself out (of course not using a file reading function) So if the language just has the really necessary things in order to make…
sub
  • 2,653
  • 3
  • 27
  • 29
33
votes
1 answer

Zip-file that contains nothing but itself?

Just out of curiosity, does there exist a valid zip-file (according to format spec) that, contains nothing but itself? Put another way, does the function implemented by unzip have a fix-point? Can I write a program to search for such a fix-point in…
aioobe
  • 413,195
  • 112
  • 811
  • 826
33
votes
10 answers

How to write a self reproducing code (prints the source on exec)?

I have seen a lot of C/C++ based solutions to this problem where we have to write a program that upon execution prints its own source. some solutions -- http://www.cprogramming.com/challenges/solutions/self_print.html Quine Page solution in many…
Abhishek Mishra
  • 5,002
  • 8
  • 36
  • 38
24
votes
2 answers

What is the "trick" to writing a Quine?

I read Ken Thompson's classic paper Reflections on Trusting Trust in which he prompts users to write a Quine as an introduction to his argument (highly recommended read). A quine is a computer program which takes no input and produces a copy of its…
calebds
  • 25,670
  • 9
  • 46
  • 74
24
votes
11 answers

Can a program output a copy of itself

I think this might be a classic question but I am not aware of an answer. Can a program output a copy of itself, and, if so, is there a short program that does this? I do not accept the "empty program" as an answer, and I do not accept programs that…
ragnarius
  • 5,642
  • 10
  • 47
  • 68
21
votes
9 answers

Programs that reproduces itself

Is it possible to make a Java program that prints its source code to a new file, and compiles it, and runs the compiled program?
Ming-Tang
  • 17,410
  • 8
  • 38
  • 76
19
votes
2 answers

How does this Python 3 quine work?

Found this example of quine: s='s=%r;print(s%%s)';print(s%s) I get that %s and %r do the str and repr functions, as pointed here, but what exactly means the s%s part and how the quine works?
Stepan Ustinov
  • 309
  • 2
  • 8
19
votes
10 answers

What are quines? Any specific purpose to have them?

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…
Arnkrishn
  • 29,828
  • 40
  • 114
  • 128
18
votes
4 answers

program that prints itself, how does it work?

I came across a program that prints itself on this site, i.e. it prints the program code. The program code is: #include char *program = "#include %cchar *program = %c%s%c;%cint main()%c{%cprintf(program, 10, 34, program, 34, 10,…
SpeedBirdNine
  • 4,610
  • 11
  • 49
  • 67
17
votes
2 answers

Shortest Ruby Quine

Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case for using a quine as an interview question. I'm not sure I agree but thats not…
AaronThomson
  • 763
  • 8
  • 19
15
votes
5 answers

Constructing quines (self-reproducing functions)

Has anyone constructed a quine ("A program that generates a copy of its own source text as its complete output": http://www.nyx.net/~gthompso/quine.htm) in R? (The [quine] tag pulls up lots of examples in Python, Java, ... but apparently none in…
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
14
votes
4 answers

Is it possible to create an HTML quine?

Per the title, is it possible to create a (non-trivial) quine in HTML? My definition of an HTML quine: A non-trivial HTML quine is one that is not null and uses at least one HTML tag, under the assumption that some string in an HTML file is…
Yuval Adam
  • 161,610
  • 92
  • 305
  • 395
14
votes
10 answers

C/C++ program that prints its own source code as its output

Wikipedia says it's called a quine and someone gave the code below: char*s="char*s=%c%s%c;main(){printf(s,34,s,34);}";main(){printf(s,34,s,34);} But, obviously you have to add #include //corrected from #include so that the…
digit plumber
  • 1,140
  • 2
  • 14
  • 27
13
votes
1 answer

Self reproducing program

main(a){printf(a="main(a){printf(a=%c%s%c,34,a,34);}",34,a,34);} How it is reproducing itself after compilation? What is the role of writing 34 in printf function?
Anil Arya
  • 3,100
  • 7
  • 43
  • 69
1
2 3 4 5 6 7