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
5
votes
4 answers

Any idea about constructing a higher order Quine program?

Here is a special Haskell program which outputs a Python program that outputs a Ruby program that outputs the original Haskell program (from http://blog.sigfpe.com/2008/02/third-order-quine-in-three-languages.html) To be more exactly, the output is…
ZelluX
  • 69,107
  • 19
  • 71
  • 104
4
votes
2 answers

Using string templates for making a quine in python?

I'm basically trying to make a quine in python and first tried with f-strings, but I quickly realized that I first have to define the variables I want to format inside the string. I then learned about string templates and figured that would be the…
Goby
  • 57
  • 4
4
votes
1 answer

C program that prints out another C program in Japanese

There was a C program written for a contest that was formatted in ASCII art as a Japanese character. When compiled and ran it printed out another program formatted in a different Japanese character, then another, then finally it printed out the…
Bryan Bueter
4
votes
4 answers

Is it possible to access the source code of a python script passed to python on standard in?

This is a bit of a random question that is more out of curiosity than any specific need. Is it possible to write some python code that will print some stuff out, including the source code itself, without having the python code stored in a file? For…
DrAl
  • 70,428
  • 10
  • 106
  • 108
4
votes
2 answers

C++ Template Quine

It is known that C++ templates are turing complete. As such it should be possible to output a quine that is essentially rendered at compile time. Does anyone know if such a quine has been written yet or where I could find one.
Jeff
  • 1,181
  • 1
  • 10
  • 17
4
votes
4 answers

Can you write a simple weekly reminder using a bash/sh script quine?

I need to set myself a reminder to attend a weekly meeting. The trouble with my company's standard reminder tool is that when it runs under wine, it pops up on an off-screen virtual desktop. I thought it would be interesting to see if I could come…
Adrian Pronk
  • 13,486
  • 7
  • 36
  • 60
3
votes
0 answers

How to write a quine while keeping the code DRY?

A quine is a program that prints its own source code without opening itself from the filesystem. Here is an example of such a quine in C#: class Q{static void Main(){var s="class Q{{static void Main(){{var…
Peter Olson
  • 139,199
  • 49
  • 202
  • 242
3
votes
4 answers

Why is this quine in C mentioned by Ken Thompson in "Reflections on Trusting Trust" not working?

This quine I saw in an article by Ken Thompson (read here) isn't reproducing the same code. I was just curious why it's not working? is the code obsolete now?. code of quine: char s[] = { '\t', '0', '\n', '}', …
Manik
  • 573
  • 1
  • 9
  • 28
3
votes
1 answer

Python 3's shortest quine. I don't get it

_='_=%r;print (_%%_) ';print (_%_) (Edit: I have recieved your input and fixed the code, thanks for the correction.) This is the shortest quine you can write in Python (I'm told). A quine being code that returns itself. Can someone explain this…
Endvisible
  • 79
  • 6
3
votes
2 answers

Is a language built specifically to not print quines still Turing complete?

"Is it possible to create a quine in every turing-complete language?" says that: Any programming language which is Turing complete, and which is able to output any string (by a computable function of the string as program — this is a…
tuskiomi
  • 190
  • 1
  • 15
3
votes
2 answers

Is this a valid quine?

def start(fileName): fileReader = open(fileName) for row in fileReader: print row, if __name__ == "__main__": import sys if len(sys.argv) <= 1: print "usage quine /path/to/file" sys.exit(-1) fileName = sys.argv[0] …
fsm
  • 407
  • 2
  • 7
  • 19
3
votes
1 answer

Attempted to make quine; does not output quotation marks

Using python 2.7. (edit at the top in case you miss something at the bottom: I have been executing the code with exec(), which makes it part of the source. More info about my usage of this is in the bottom of this post) Recently, I have taken an…
Quojil
  • 107
  • 1
  • 8
3
votes
2 answers

Explanation for perl quine

I found this quine recently $a='$a=%c%s%c;printf($a,39,$a,39,10);%c';printf($a,39,$a,39,10); And I just can't get my head around it. I've found no explanation on google/SO for this particular one, so I'm hoping that someone could explain to me how…
Vince
  • 1,517
  • 2
  • 18
  • 43
3
votes
1 answer

A macro that invokes itself prints itself?

The following program looks like a C macro that calls itself. #define q(k)int puts();int main(){puts(#k"\nq("#k")");} q(#define q(k)int puts();int main(){puts(#k"\nq("#k")");}) It compiles and runs fine. It prints itself out. Is this code really C?…
jxh
  • 69,070
  • 8
  • 110
  • 193
3
votes
1 answer

How are complex multi-quines written?

I am defining a multi-quine as: A set of n programs in n different programming languages, such that each one of them, when given no input, outputs its exact source code, and when given n as input, output the source code of the *n*th program. This…
Swadq
  • 1,837
  • 2
  • 15
  • 25