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
13
votes
3 answers

Is function(){} a true quine?

After poking around on the internet I wasn't able to find anyone who had written a quine in R (Edit: since writing this, have found several on SO, but am still interested in this one). So I figured I'd try my hand at coming up with one myself. My…
Empiromancer
  • 3,778
  • 1
  • 22
  • 53
13
votes
4 answers

How does this program duplicate itself?

This code is from Hacker's Delight. It says this is the shortest such program in C and is 64 characters in length, but I don't understand it: main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);} I tried to compile it. It compiles…
PDP
  • 143
  • 9
12
votes
1 answer

Quine program without main()

I came across this little quine program, written without main method: enum f { f; System z; String s="enum f{f;System z;String s=%c%s%1$c;{z.out.printf(s,34,s);z.exit(0);}}"; {z.out.printf(s,34,s); z.exit(0);} } Can somebody explain how…
Uros K
  • 3,274
  • 4
  • 31
  • 45
10
votes
3 answers

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"

is it possible to write a program which prints its own source code utilizing a "sequence-generating-function"? what i call a sequence-generating-function is simply a function which returns a value out of a specific interval (i.e. printable…
guest
  • 101
  • 3
8
votes
3 answers

Program which source code is exactly the same as its output

The more I try to understand this perplexed enigma the more I want to give up. char *s = "char *s = %c%s%c; main(){printf(s,34,s,34);}"; main(){printf(s,34,s,34);} How is happening for this one-line source code to generate exactly the same output…
Imobilis
  • 1,475
  • 8
  • 29
7
votes
4 answers

The missing quines: Visual Basic (for Applications)

Today I surfed some random geek-stuff articles on wikipedia to get my daily dose of useless knowledge. I stumbled accross quines, which are programs that print their own source-code. I found that a great way to make my brain hurt, so I began working…
das_weezul
  • 6,082
  • 2
  • 28
  • 33
7
votes
3 answers

What is quine meant for?

So I just came across the term Quine on Wikipedia and cannot figure out what the heck it is meant for. I'm more than confused about it. Are there any real-world uses for it?
tomsseisums
  • 13,168
  • 19
  • 83
  • 145
6
votes
3 answers

C# Quine Problem

I am trying to understand how this piece of self-replicating code works (found here), but the problem is I can't get it to run as-is: class c { static void Main(){ string s = "class c{{static void Main(){{string…
JohnIdol
  • 48,899
  • 61
  • 158
  • 242
6
votes
1 answer

Haskell Quine: "ap" Monad

What is the proper way to use the "ap" monad in Haskell? I want to do something similar to this: main = (putStr . ap (++) show) "main = (putStr . ap (++) show) " but I get the error "Not in scope: 'ap'." Using "import Control.Monad" does…
GossJ
  • 69
  • 8
6
votes
4 answers

Java application that prints its own source code

I have a little quiz that I cannot solve by myself. I want to build a program that will print its own source code with java. Anyone knows how to do this? Like this example: public class SourcePrint { private static final long serialVersionUID =…
user1481602
  • 77
  • 1
  • 1
  • 2
6
votes
2 answers

Understanding ruby quine

I have found this code block on Wikipedia as an example of a quine (program that prints itself) in Ruby. puts <<2*2,2 puts <<2*2,2 2 However, I do not get how it works. Especially, what I do not get is that when I remove the last line, I get this…
knub
  • 3,892
  • 8
  • 38
  • 63
5
votes
1 answer

How does this superb quine work?

Another SO question mentions a fantastic quine by Yusuke Endoh. A quine is a computer program which produces a copy of its own source code as its only output; this one does it with a twist. A must-see. But I can't figure out how it works. Any…
steenslag
  • 79,051
  • 16
  • 138
  • 171
5
votes
7 answers

quine (self-producing) SQL query

This is a very interesting wiki article about programs that print their own source code without any access to physical source file (in the filesystem). Examples in the articles include C and Scheme quine programs (yeah, it appears they are called…
Armen Tsirunyan
  • 130,161
  • 59
  • 324
  • 434
5
votes
2 answers

Is it possible to write a Java printf statement that prints the statement itself?

Is it possible to have a Java printf statement, whose output is the statement itself? Some snippet to illustrate: // attempt #1 public class Main { public static void main(String[] args) { System.out.printf("something"); } } This prints…
polygenelubricants
  • 376,812
  • 128
  • 561
  • 623
5
votes
3 answers

How could a quine in my programming language look?

I have created a turing-complete programming language (already proven) so it must be possible to write a quine for it, right? But all quines I know store their source code in a string and then replace a special character in it using something like…
ads
  • 53
  • 2