Can a program output a copy of itself

前端 未结 11 1141
萌比男神i
萌比男神i 2020-12-29 23:07

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?

11条回答
  •  抹茶落季
    2020-12-29 23:38

    Michael Sipser’s “Introduction to the Theory of Computation” explains in one of the chapters how to construct a quine. I have recently written a Java program based on that idea and posted it at : http://bornagainprogrammer.net/2009/11/07/hello-world-from-the-tm-self/

    I'd suggest you get hold of that book and try implementing the program yourself in your favorite language. There are lot of other fun theorems in that book.

    -kiran

提交回复
热议问题