Thread overview
Quine in D
Feb 21, 2005
zwang
Feb 21, 2005
zwang
Feb 21, 2005
Stewart Gordon
February 21, 2005
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?
February 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.
February 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.