Can a program output a copy of itself

前端 未结 11 1152
萌比男神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:31

    In the language invented by Jon Skeet the following operator prints "Hello, world!\n".

    h
    

    I can make a modification of this language so that the following program prints "Hello, world!\n":

    Hello, world!
    

    So that's the program that prints itself.

    Oh, you feel something strange about it, while it has a precise and correct mathematical definition? That's your problem. "I won't accept..." ha! Mathematics does accept, and she's the mistress I serve, so I post this answer.

提交回复
热议问题