Quine is a self reproducing code. For example if the code in groovy looks like:
def s = 20
When i run the above code, i should get the program statements as my outputs. So the above code should produce:
def s = 20 //as this is my input..
As I have seen in Groovy Console, i came to know groovy supports Quine :
s='s=\\\';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*2';s[0..1]+s[3]+s[0..1]+s[2]*6+s[3..-1]*2
But I don’t know how it works! Could any one say me, how the code in the above link works?
Thanks in advance!
The code in question is:
So, the left statement defines a string, then the right statement adds together different bits of the String:
If we add the following to print out what it’s doing:
we get the output:
And if you add all those strings together, you get the original program.