Hello Monks,
This is my first attempt at (deliberate) obfuscation.
It's a version of
John Conway's Game of Life.
For those unfamiliar with the game, the rules are simple.
You define a grid and initialize each cell to either living or dead.
Then you traverse the grid checkin the surrounding cells.
If the current cell is alive it stays alive as long as 2 or 3 of its
neighboring cells are alive.
If the current cell is dead it can come to life if exactly 3 neighbors are
alive.
This code can take an argument to define the grid size, 20 seemed like a good size for my terminal window.
map{sub __;$/=$_;sub _;map{$g[$/][$_]{c}=rand(time)%2;push@{$g[$/][$_]
+{n}}, (
\$g[_$/][ $_]{c} =>\$g[__$/][ $_]{c}=>\$g[ $/][_$_]{c}=>\$g[ $/][__
+$_]{c},
\$g[_$/][_$_]{c} =>\$g[_ $/][__$_]{c}=>\$g[__$/][_$_]{c}=>\$g[__$/][__
+$_]{c},
)}(0..$s)}(0..($s=(shift or 15)-1));sub __{(($m=shift)+1)<=$s?$m+1:0}
+sub _ {
(($m=shift)-1)>=0?$m-1:$s}__;__;while(1){map{$/=$_;map{print$g[$/][$_]
+{c}; $u
+=$$_ for(@{$g[$/][$_]{n}});$t[$/][$_]{c}=$g[$/][$_]{c};$t[ $/][$_]{c}
+=($u==3
?1:($u !=2?0:($t[$/][$_]{c}==1?1:0)));__;$u=~s _.__;}(0..$s);print"\n"
+;}(0 ..
$s);print"\n";map{$/=$_; map{$g[$/][$_]{c}=$t[$/][$_]{c}}(0..$s)}(0..$
+s);_;_;
__;_;__;_;__;_;__;_;sleep 1}__;_;__;_;_;__;_;__;_;_;__;_;__;_;_;__;_;_
+_;_;__;
A few notes on the code...
As I mentioned before, I haven't done any deliberatly obfuscated code before,so this was an interesting experiment for me. I'm actually not too happy with it,
to be honest. It mostly is just using all those poor programming practices
I normally tell people not to do. I had hoped to do something really clever
but alas, this is all I could come up with. Compared to some of the other nodes in this section it's not really even obfuscated.
I'm interested in what other monks might think of it,
and would love some suggestions.
Thanks,
Ira,
"So... What do all these little arrows mean?"
~unknown
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.