[R] Some Programming Humor - Quine
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Wed May 14 20:50:00 CEST 2003
Well I managed to modify a javascript quine on the quine web page to
create this monster - simply stick it all on one line in a file - I've
split it here for an attempt at clarity:
a=1:10;a[1]='a=1:10;';a[2]='[';a[3]=']';a[4]='\'';a[5]='\\';a[6]='=';a[7]='a';a[8]=';';a[9]='';
a[10]='for(i in 1:10)cat(ifelse(i==1,a[1],a[9])
,a[7],a[2],i,a[3],a[6],a[4],ifelse(i==4||i==5,a[5],a[9]),
a[i],a[4],a[8],ifelse(i==10,a[10],a[9]),sep=a[9])';for(i in 1:10)
cat(ifelse(i==1,a[1],a[9]),a[7],a[2],i,a[3],a[6],a[4],
ifelse(i==4||i==5,a[5],a[9]),a[i],a[4],a[8],ifelse(i==10,a[10],a[9]),sep=a[9])
This passes the quine script test:
$ R --slave < q2.R >q2o.R
$ diff q2.R q2o.R
<nothing!>
$
I'm sure if I understood it I could make it better...
Original javascript version by: Geoffrey A Swift (blimey at toke.com)
From: http://www.nyx.net/~gthompso/quine.htm
Baz
More information about the R-help
mailing list