It always amazes me when I read about how people write a C program that print itself. The self-printing program, or more formally,
quine, prints out its source code.
Having used Groovy for a while, I wonder if there is any self-printing Groovy program on the Internet. After some googling around, I found some Java programs on this
page. After spending about 15 minutes, I came up with what I think is the first self-printing Groovy program to date. I used Bertram Felgenhauer's 2nd example as my starting point. Here is my version in Groovy (the code is written in one line):
class S{public static void main(a){def s="class S{public static void main(a){def s=;char c=34;println(s.substring(0,41)+c+s+c+s.substring(41));}}";char c=34;println(s.substring(0,41)+c+s+c+s.substring(41));}}
See if you can make it shorter.
Updates
Chrigel suggested the removal of "public". I have to adjust the parameter to substring() too. Here is a shorter version (195 bytes):
class S{static void main(a){def s="class S{static void main(a){def s=;char c=34;println(s.substring(0,34)+c+s+c+s.substring(34));}}";char c=34;println(s.substring(0,34)+c+s+c+s.substring(34));}}
paulk's version is 97 bytes:
def s="def s=;char c=34;println s[0..5]+c+s+c+s[6..-1]";char c=34;println s[0..5]+c+s+c+s[6..-1]
paulk's 2nd version is 46 bytes:
s="s=%c%s%c;printf s,34,s,34";printf s,34,s,34
paulk's 3rd version is 42 bytes. Keep going, paulk!
s='s=%c%s%1$c;printf s,39,s';printf s,39,s
Gavin Grover found a 38-char solution at
http://golf.shinh.org/p.rb?Quine:
printf _='printf _=%c%s%1$c,39,_',39,_
Are we approaching the limit?