[net.text] Cute little liar program

lwall@sdcrdcf.UUCP (Larry Wall) (06/27/86)

In article <301@zuring.UUCP> dik@zuring.UUCP (Dik T. Winter) writes:
> This brings on another question.  Is it possible to create non-trivial
> input to {t,d}itroff that reproduces itself?  (By non-trivial I mean
> it should contain at least one line starting with period or apostrophe,
> because, as a silly co-worker pointed out to me, the empty file
> reproduces itself.  Also .sy should not be permitted.)

Well...

I took this as a challenge, and wrote something that may do what you want.
I don't have {t,d}itroff real handy, but I did come up with a self-reproducing
nroff script, so you might try it out with {t,d}itroff and see if it works.
Not only was it NOT trivial, it was durn near impossible!  I had to get rather
devious.  If there's an Obfuscated Nroff Code Contest in the near future,
consider this my entry for it.

Since there may be some people who wouldn't try doing this until they find
out that it IS possible, I'll just say to them that it is.  Have fun.  So that
I don't spoil their fun, the one I wrote follows both in uuencoded and rot13
format for those who aren't interested in trying to solve the problem
themselves.  I had another version that used '.eo' to reduce the number of
escape characters, but it came out to the same number of bytes, and more lines,
so I won't post it.  If anyone can shorten this one, they're welcome to try.
To run this,

	uudecode this_article
	nroff self.n >self.out
	cmp self.n self.out

(By the way, I leave you with the challenge to make a C/nroff program that
compiles without error and prints out "hello world\n" either way.  Yes, it
can be done.  If anything it's easier than the self-reproducer, but that's
not saying much.  Definitely an AHA! type problem.)

Larry Wall
sdcrdcf!lwall

THE UUENCODED VERSION:

begin 664 self.n
M+F5C.`HN96U:6@HN;G)Y>3$P,#`M,3(*+FYR>GHQ,#`M,0HN;F8*+F1E6%@*
M+G1R.#AN*'EY"C@X(3@X(3@X)#$*+G1R.#AN*'IZ"BYA;5I:+BX*.#@A.#@A
M+EA8.#@D,0HN;G)N;#`M,0HN+BX*+BX*+EA8+F5C.0HN6%@N96U:6@HN6%@N
M;G)Y>3$P,#`M,3(*+EA8+FYR>GHQ,#`M,0HN6%@N;F8*+EA8+F1E6%@*+EA8
M+G1R.3EN*'EY"BY86#DY(3DY(3DY)#$*+EA8+G1R.3EN*'IZ"BY86"YA;5I:
M+BX*+EA8.3DA.3DA+EA8.3DD,0HN6%@N;G)N;#`M,0HN6%@N+BX*+EA8+BX*
`
end

(***SPOILER WARNING***)
Reading the ROT13 version may give you clues you don't want, despite the
encryption.

THE ROT13 VERSION:

Abgr gung gur frpbaq unys vf vqragvpny gb gur svefg unys, jvgu gur
rvtugf genafyngrq gb avarf naq n .KK cercraqrq.

.rp8
.rzMM
.aell1000-12
.aemm100-1
.as
.qrKK
.ge88a(ll
88!88!88$1
.ge88a(mm
.nzMM..
88!88!.KK88$1
.aeay0-1
...
..
.KK.rp9
.KK.rzMM
.KK.aell1000-12
.KK.aemm100-1
.KK.as
.KK.qrKK
.KK.ge99a(ll
.KK99!99!99$1
.KK.ge99a(mm
.KK.nzMM..
.KK99!99!.KK99$1
.KK.aeay0-1
.KK...
.KK..