.sig files
Back in the 80's there was a tradition of writing short, obfuscated code that can be fit into a Usenet signature, typically 4 lines of 72 characters each, and in this spirit, I've been trying to write neat pieces of code that fall under this rule. The code usually does some simple task, or draws something interesting.
XFace
X-Face: #4ZE;*$mT}MAuh#lOe%3[}(DJkQ"4yU'6=G:hbn1]Q"RkDJ)}`S68v80V\tj'%+Z"#K".mP
e+[ym#PK&n49j2a"TgG"8Mt-"V#:EF\}")inf5|]}$]Rgp($R%a?MU`:jl$GK|9dofP(c^mFMW_^Pc
LI>Z5.n>XX/D}n6Xn7xQ)RW%JeNmJ|qby2L_uwGpZ(xWIyo50*l0R"i*?<E|G\aj]k1bLFIjN5O0T5
JQ7xg6F'XUqQYGCzA?HEwu<BpZBNNrif-c,J=+gKy3|_bjtGDmcVP?N5ELvqjNK:N'V?UpqVES:Q%}
rule30
#!/usr/local/perl
$n=$i='0'x306 ."1".'0'x306;$z="%!\nnewpath ";for($c=0;$c<792;$c++){$z.="0
$c moveto ";foreach(split("",$n)){$z.="1 0 r".($_?"lin":"mov")."eto "}$n="";
foreach(1..length($i)){$n.=((30>>((substr$i,-3,3)&7))&1);$i=(substr$i,1)
.(substr$i,0,1);}$n=(substr$n,2).(substr$n,0,2);$i=$n;}print$z."stroke";
Written in perl, this code produces a cellular automaton identical to the one mentioned in the June 2002 Wired magazine article on Stephen Wolfram. The code produces a postscript file which can be viewed with ghostscript or directed to a file and printed out.
The name comes from the name of the cellular automation that Wolfram gives as an example for complexity ithat can arise from simple predetermined rules. Each line on the paper represents a snapshot from a universe made up of a single thin ring of adjoining cells. Bacteria can occupy a single cell at a given time, either alive (black) or dead (white). Starting with a bacteria sitting alone in its universe at the bottom of the page, each line up the page represents the next successive time step in this universe, where bacteria in a given cell are either created or destroyed according to how many bacteria there were in the current cell and its two adjoining cells.
Wolfram's point is that even knowing all the rules of this very simple universe, suprising and beautiful complexity can be generated. The 30 refers to a particular set of rules that produce a very interesting pattern, although the number can be anywhere from 1 to 255. Feel free to change the value of 30 on the third line to whatever takes your fancy. I do suggest even numbers, though, and it's not too difficult to add a loop to check out all the other possible rules. Interesting ones I've found are: 18, 86 and 182.
rule30.pl | gv - or rule30.pl > file.ps
for a printable version.
This falls foul of the 72 by 4 lines rule by about 6 characters. I can't seem to avoid using the substr function a lot, and this take up a lot of room.
Slashdot sig v1
#!/usr/bin/perl -w
print map{$_==78?"\n":" "x($_&15)."_|"x($_-16>>5)}unpack"C*",
"b164N1vqrc22Np01a32121212N13c12121212N13q22qcsN/?N/mN"
The computer news site Slashdot allows you to comment on news stories and have a signature block added to your post. The limit is 120 characters, so I wrote some perl code that produced my nickname for the site. It weighs in at 117 characters (minus the linebreak I've put in), although I am toying with a regular expression that may cut it by a couple of characters further...
Slashdot sig v2
A more advanced version of this code produces a more complicated result. This won't go in a slashdot signature, but could be used in a more general one. 186 characters if wrapped up onto a single line.
#!/usr/bin/perl -w
$_="ueeurcujcmgnmecbecmeefnenneueeumgnmcnnbejfhnfhlahlfnngnefve
faeeafefeffeeeadeeeade`ng{{{{{{{beeeag";s/(.)/$c=ord$1&7;print
(($c==7)?"\n":" "x(3&(ord($1)>>3)).substr".\/<>\\_|",$c,1)/ge
Last updated: Wednesday January 02, 2008