A quine is a computer program which takes no input and produces a copy of its own source code as its only output. There are many trivial quines in Mathematica:
In[1]:= "Hello world"
Out[1]= "Hello world"
In[2]:= 3.14
Out[2]= 3.14
In[3]:= f[x]
Out[3]= f[x]
where f
and x
are undefined symbols; and some more
In[4]:= Hold[N[\[Pi]]]
Out[4]= Hold[N[\[Pi]]]
These are all trivial. I was thinking that perhaps a more interesting challenge for Mathematica was a multiquine. This is a program A that outputs another program B, distinct from A, such that when B is exectuedexecuted, the output is A. Multiple levels of depth are also allowed: Thus one might have a program that when executed outputs a distinct program that when executed outputs another program distinct from the first two ... that when executed outputs the original program.
There are also multiquines that output a distinct program in a different language, such that when this program is executed, the output is the original program.
QUESTION (Though more of a challenge): Can you come up with a multiquine for Mathematica?