quine

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

寵の児 提交于 2019-11-27 14:26:47
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 <stdio.h> //corrected from #include <stdlib.h> so that the printf() could work. Literally, since the above program did not print #include <stdio.h> , it is not a solution (?) I am confused about the literal requirement of "print its own source code", and any purpose of this kind of problems, especially at interviews. The trick here is that most compilers will compile without requiring you to include stdio.h .

Shortest Ruby Quine [closed]

北城余情 提交于 2019-11-27 13:48:58
问题 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 what this question is about. He goes on to construct a quine in Ruby and refactor it to make it shorter. He then challenges the reader to try to make it even shorter. I played around with it for a while and came up with the following: s="s=;puts s[0

Programs that reproduces itself

一曲冷凌霜 提交于 2019-11-27 03:11:36
问题 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? 回答1: Yes, it is possible. A trivial implementation would be: have the source code contain itself in a string, save the string to a file and fill its own string with the same string (otherwise, the initial string would be of infinite size, due to the recursive manner of this implementation), compile the file, and run the compiled file (which will, in turn, do the