Write a program that writes an exact copy of itself without using any outside references.
You can specify your own programming language.
It can define and use variables, assignment, and arithmetic: X = Y + 5, or X = "Myself".
It can use decision statements, such as IF, ELSE, SWITCH.
It can use any sequence of execution controls, like GOTO, or loops like DO WHILE, DO UNTIL, REPEAT x TIMES.
It can use WRITE, or PRINT to produce the output (its own text).
However, it cannot READ, nor it can refer to an absolute, or any outside address in memory. For that matter, let's prohibit the use of pointer variables.
No solutions over 10 lines long, please.
Perhaps, it is harder for people unfamiliar with computer programming to solve the problem. But I think, most anyone would easily understand the correct solution.
Question
Prime
Write a program that writes an exact copy of itself without using any outside references.
You can specify your own programming language.
It can define and use variables, assignment, and arithmetic: X = Y + 5, or X = "Myself".
It can use decision statements, such as IF, ELSE, SWITCH.
It can use any sequence of execution controls, like GOTO, or loops like DO WHILE, DO UNTIL, REPEAT x TIMES.
It can use WRITE, or PRINT to produce the output (its own text).
However, it cannot READ, nor it can refer to an absolute, or any outside address in memory. For that matter, let's prohibit the use of pointer variables.
No solutions over 10 lines long, please.
Link to comment
Share on other sites
42 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.