digitalmars.D - Quine in D
- zwang (7/7) Feb 21 2005 Hi,
- zwang (6/14) Feb 21 2005 Ok, here comes a 86-character quine:
- Stewart Gordon (9/19) Feb 21 2005 I wrote a few that aren't shorter, but make use of D's features:
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
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
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