Obfuscated dc

(4 years ago, I wrote: "I never considered myself a dc programmer. I tried it out and it was a piece of cake, so here we go - a few slices of that cake. Warning - this is probably the saddest area of my website!")

Actually, when I first tried it 4 years ago, I thought I was smart; however, I now know that to not be the case. In 2001, I finally made a dc breakthrough and all of my programs are shorter than they used to be!

dc programs

Here I show you the evolution of my dc, so that maybe you can learn from the discoveries and tricks that I use!

The benchmark

I once saw someone with a .sig that was something like:
dc -e'[q]sa[lnd0=ad256%P256/sndx]d38672306508690984187480423879340810695371422172621438450122222581106488326928418628922846528763278301374629425838469051136688555534710439430775050842624437012774600003400snx'

I'd first optimise that thusly:
dc -e'[q]sa16i[lnd0=ad100%P100/sndx]dA3F444F4F57204B4355484320444C554F43204B43554843444F4F572041204649204B43554843204B43554843444F4F57204120444C554F5720444F4F57204843554D20574F48snx'

That's still far too wasteful. I may be tempted to do:
dc -e'[q]sa[lnd0=ad57%31+P57/sndx]d467128699149583256523155276884835114697030545269337006354016745353877175952972040091585417319888708113050086277579881632231snx10P'

But even that still is too wasteful. Instead I would do:
dc -e'[q]sa16i[lnd0=ad39%1F+P39/sndx]dB4E65EB0986982695A991E036BB7A9B2A22A998DAE4FEF61E8F438C978568939DD5CFCEA85B778FFE4151D4BD89A242F14D1E7snxAP'

Until now, that is (now being 19/10/2001). This is what I'd do now:
dc -e'[q]sq16i33B24A4611BA0CE85E5981C76B01F21064F549987F8204D0708FEB886ED1997D6D565EFED71D3AE96BAC2F6FE34ADAD478FC30[d0=q38~20+Plxx]dsxxAP'

I hope you'll agree I've achieved a reasonable character efficiency? If you can make something smaller, please let me know

Update - 2011-05-26:


[Arzka] Are you the guy behind fatphil.org?  We discussed about DC and someone pointed your page, and it inspired me to
           optimize your WOODCHUCK... dc skripts. And you asked to tell you shorter solutions.  My first try is 9 char
           shorter than yours
[Arzka] dc -e'16i47BEE058EA81808CABC6058EA8191EFB80203240B1D50302C7540C8F7DC01011957DC047BEE040EAD05DE8[20-]sb[20~40+d40=bPd0<a]dsax3FPAP'
-- Where Arzka is one Ari Saastamoinen
Nice one, Ari! Now I'm going to work out how it works! 20- looks like an interesting start.

Update - 2013-07-16:
Oh dear - Ari missed a 1-character optimisation!
dc -e'16i47BEE058EA81808CABC6058EA8191EFB80203240B1D50302C7540C8F7DC01011957DC047BEE040EAD05DE8[20-]sb[20~d0=b40+Pd0<a]dsax3FPAP'

Other Phrases

dc -e'[q]sq16iAD11A78FF200E6AC455E5C0572A5438A87287C5870336D69E2DFCC81A90F9A99C3DB237ECF8D87A0E0D57B53429DB7B4A9F753098A916BD5CA1D950CD31BA5E9CAFAC268BAE928310B3E8891154FD11A265301D59E189995C4A58B175E1B3FB[d0=q5A~20+Plxx]dsxxAP'
dc -e'[q]sq16i69FA9FA99F5C757CFD7C81EEADF0ED0A1839B08223CFE7C[d0=q55~20+Plxx]dsxxAP'
dc -e'[q]sq16i3ADAAA893BE8B8DB1162094FD51711722A89C7[d0=q6D~9+Plxx]dsxx'
dc -e'[q]sq16i6C8964EBBE6E3C[d0=q2C~28+Plxx]dsxxAP'

The Obligatory Quine

19/10/2001 was a good day - I managed to work out how to quine in dc!

[91PP93P[dx]P]dx
Go into dc, and run that program!

It's fairly obvious how it works, so I'd be surprised if it had never been done before. However, it ain't yet on Gary P. Thompson II's list or Ben Olmstead's list. So I am fairly confident that I'm certainly not treading on too many toes by claiming it as mine. I will retract that claim as soon as anyone provides any evidence to the contrary, obviously.

Update 24/09/2004 - It appears that the above isn't entirely original. A very similar version was posted to a French newsgroup in 1999 by one David Madore, message ID 7j72hj$ps7$3@clipper.ens.fr. He includes a newline in his, but the script doesn't require a newline, so mine is 4 characters shorter. I am entirely convinced that either these pages did not exist back in 2001, even though as can be seen the contents of the former predates that by 2 years, or that the search engines I used, google et al. really didn't do a very good job at all. (The fact that Ben and Gary weren't aware of the pages backs that up.)

Update 17/02/2009 - It appears I didn't include a new-lined quine when really I ought to have done: [91PP93P[dx]PAP]dx This is of course 1 character shorter than David Madore's (as I added 2 non-space characters and one newline to the above).

The 'Oh No, Not Again!' Utterly Gratuitous Quine

24/09/2004 was a wacky day - I decided that the dc quine which simply reproduces itself wasn't that useful in the real world as most people aren't running dc the whole time. What is obviously needed is the shell command line that uses dc to reproduce itself! This is different from the simply shell command line that reproduces itself, obviously. (I did this before finding out that the previous pure dc one was not entirely original, for reference)

dc -e'[[dc -e]P39P91PP93P[dx]P39PAP]dx'

And with that, I shall retire. No more quines for me, honest. Ever.

Update 31/07/2013 - with fewer numbers, and more letters, or with more numbers, and fewer letters:

dc -e'[[dc -e]P39dP91PrP93P[dx]PPAP]dx'
dc -e'[[dc -e]P10075PP93P[dx]P39PAP]dx'

Update 10/08/2019 - Let's just take another character off by exploiting what I consider to be a terrible hack:

dc -e'[[dc -e]PA075PP93P[dx]P39PAP]dx'
dc -e'[[dc -e]PA06FPP93P[dx]P39PAP]dx'
dc -e'[[dc -e]PA06FPP8DP[dx]P39PAP]dx'

Yup, that's "ay-thousand and seventy-five", "ay-thousand and sixty-eff", and "eighty-dee"! OK, really, that's the last time I'm going to look at quines in dc. I promise.


Another hastily constructed page by Phil Carmody
Home / ob/obdc.html