This was inspired by
this obfuscation and
this one, which present golfed obfuscations of
Conway's Game of Life. It seemed like a natural extension to write it in Perl/Tk, and then try to golf it down. (It runs a little slower than it would if it were optimized for speed, which would naturally take more code).
Update 3: You need to have Perl/Tk installed for this program to work.
s''map{$j
^=1;map{$g{$j}{
$_}=1}split//}spl
it"/",$G||="23/3";s
ub#g{$z=pop;$r=\$C[
64*$x+$y];$Q=$x<0||
$x>63||$y<0||$y>63?
0:$$r;if($z>=0&&$
Q!=$z){$$r=$z;$
M=512*$x+
8*$y;$I=$
I[$M]and$c->del
ete($I);$I[$M]=cr
eateOval$c(3+8*$x,3
+8*$y,9+8*$x,9+8*$y
,-f=>$z?"blue":$N,o
utline=>$N)}$Q}use#
Tk;$m=new#MainWin
dow(title=>$G);
$c=$m->Ca
nvas(w,51 4,he,514) ->pack;af
ter$m(1,sub{$N= cget$c(bg);@S=0 ..63;map{$a=2+8
*$_;@D=(2,$a,515, $a);map{createLin e$c(@D);@D=($a,@D
);pop@D}7..8}@S,64; $F?do{open(_,$F);ma p{$x=0;map{g(/@/);$
x++}split//;++$y;}< _>}:map{$x=$_;map{$ y=$_;g(1>rand#4)}@S
}@S;{for$p(@S){map{ $q=$_;$t=0;for$v(-1 ..1){map{$x=$p+$_;$
y=$v+$q;$g=g(-1);$_ ||$v#or$G=$g;$t+=$g ;}(-1..1)}$N[64*$p+
$q]=$g{$G||0}{$t- $G}}@S}for$x(@S){ map{$y=$_;g+$N[64
*$x+$_]}@S}upda te$m;redo}});Ma inLoop';s#\s##g
;s&#& &g; ($F,$G)=@ ARGV;eval
But wait, there's more... If you give a single filename argument (other than "0", which is ignored), it will read the starting setup from that file, where each line (of up to 64 lines) contains up to 64 characters; '@' = living cell, and anything else is non-living.
And, if you specify a second command-line argument, it changes the rules! This link describes the more interesting variations of the super-set of John Horton Conway's game (which can be classified as "23/3" life).
A second argument of "23/34", for example, would switch the rules to those of HighLife, whereas "34678/3678" would use the rules of Day & Night. (You can always give a first argument of "0" to generate a random pattern instead of reading from a file).
Update: Here's an example of a file (the pattern is called a "Gosper Glider Gun") which, when passed as the first argument to the obfuscation (eg.
life.pl gg.txt), causes an never-ending stream of "gliders" to be produced:
.......................................
.........................@.............
.......................@.@.............
.............@@......@@............@@..
............@...@....@@............@@..
.@@........@.....@...@@................
.@@........@...@.@@....@.@.............
...........@.....@.......@.............
............@...@......................
.............@@........................
And you can try different rules, sometimes with surprising results.
For example, try using the same file, but substitute the "1357/1357 = Replicator" pattern: life.pl gg.txt 1357/1357. The results are completely different.
Or try: life.pl 0 2345/45678 to see the results of "Walled Cities" rule ("2345/45678"), applied to to a random pattern.
Update 2: I can't resist adding another one that I just now tried for the first time (again, from this page).
This one is called "Diamoeba (5678/35678)", and works best with a pattern that contains many living cells close together; for example:
................................................
................................................
................................................
................................................
................................................
................................................
................................................
................................................
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
.................@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Assuming the above file is called "block.txt", you can see the results with: life.pl block.txt 5678/35678.
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.