www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Quine in D

reply zwang <nehzgnaw gmail.com> writes:
Hi,
I wrote a quine (a program that produces itself) in D.
<code>
char*s="char*s=void main(){printf(`%.*s%c%s%c;%s`,s[0..7],34,s,34,s+7);}";void
main(){printf(`%.*s%c%s%c;%s`,s[0..7],34,s,34,s+7);}
</code>

131 characters seem to be too long, though.
Anyone can come up with a shorter version?
Feb 21 2005
next sibling parent zwang <nehzgnaw gmail.com> writes:
zwang wrote:
 Hi,
 I wrote a quine (a program that produces itself) in D.
 <code>
 char*s="char*s=void main(){printf(`%.*s%c%s%c;%s`,s[0..7],34,s,34,s+7);}";void
main(){printf(`%.*s%c%s%c;%s`,s[0..7],34,s,34,s+7);}
 </code>
 
 131 characters seem to be too long, though.
 Anyone can come up with a shorter version?
Ok, here comes a 86-character quine: <code> void main(){char*s="void main(){char*s=%c%s%c;printf(s,34,s,34);}";printf(s,34,s,34);} </code> Sadly enough, not a single new feature of D is exhibited.
Feb 21 2005
prev sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
zwang wrote:
 Hi,
 I wrote a quine (a program that produces itself) in D.
 <code>
 char*s="char*s=void 
 main(){printf(`%.*s%c%s%c;%s`,s[0..7],34,s,34,s+7);}";void 
 main(){printf(`%.*s%c%s%c;%s`,s[0..7],34,s,34,s+7);}
 </code>
 
 131 characters seem to be too long, though.
 Anyone can come up with a shorter version?
I wrote a few that aren't shorter, but make use of D's features: http://smjg.port5.com/wwwep/quines/d.html These were both written before we had writef. I think I might have since tried writing one using writef, but don't have it to hand at the mo. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Feb 21 2005