quine

Zip-file that contains nothing but itself?

戏子无情 提交于 2019-12-02 17:58:17
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 a intelligent (not-exhaustive) way? I've thought about the opposite as well, i.e. if zip has a fix-point, but presumably a file can be compressed in different ways (different algorithms, different levels of compression and so on), thus whether or not f = zip(f) holds for some file f is probably implementation dependent. Since the zip-compression is

program that prints itself, how does it work?

♀尐吖头ヾ 提交于 2019-11-30 06:29:30
I came across a program that prints itself on this site, i.e. it prints the program code. The program code is: #include <stdio.h> char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c"; //what is this line doing, what is the use of %c and %s and what properties of %c and %s are being used here? int main() { printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); //what is this print function doing, and how? return 0; } And the explanation given is: The two key tricks here are using a

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

佐手、 提交于 2019-11-30 01:58:20
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 it turing complete (I would prove that by translating Brainf*ck code to it), like output, variables, conditions and gotos (hell yes, gotos), can I try writing a quine in it? I'm also asking this because I'm not sure that a quine directly fits into Turing's law that the turing machine is capable of any computational task. I just want to know so I don

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

走远了吗. 提交于 2019-11-29 20:08:07
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 languages There are many more solutions on the net, each different from the other. I wonder how do we approach to such a problem, what goes inside the mind of the one who solves it. Lend me some insights into this problem... While solutions in interpreted languages like perl, php, ruby, etc might be easy... i would like to know how does one go about

Can a program output a copy of itself

心已入冬 提交于 2019-11-29 11:05:10
问题 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 have access to there own source code. Rather, I am thinking something like this: int main(int argc, char** argv){ printf("int main(argc, char** argv){ printf... but I do not know how to continue... 回答1: Yes. A programme that can make a copy of

program that prints itself, how does it work?

拟墨画扇 提交于 2019-11-29 06:10:37
问题 I came across a program that prints itself on this site, i.e. it prints the program code. The program code is: #include <stdio.h> char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%cprintf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c return 0;%c}%c"; //what is this line doing, what is the use of %c and %s and what properties of %c and %s are being used here? int main() { printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10); //what is this print

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

房东的猫 提交于 2019-11-28 22:20:47
问题 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 it turing complete (I would prove that by translating Brainf*ck code to it), like output, variables, conditions and gotos (hell yes, gotos), can I try writing a quine in it? I'm also asking this because I'm not sure that a quine directly fits into

Shortest Ruby Quine [closed]

别来无恙 提交于 2019-11-28 21:25:07
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,2]+34.chr+s+34.chr+s[2,36]";puts s[0,2]+34.chr+s+34.chr+s[2,36] This is the first time I have ever

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

跟風遠走 提交于 2019-11-28 15:21:30
问题 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 languages There are many more solutions on the net, each different from the other. I wonder how do we approach to such a problem, what goes inside the mind of the one who solves it. Lend me some insights into this problem... While solutions in

Programs that reproduces itself

核能气质少年 提交于 2019-11-28 09:45:17
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? 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 very same). Non-trivial implementations are significantly harder. Update: Okay, might as well make it autorun.