Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

So I was golfing down my code for my Game of Life and had gotten down to 287 characters. But I could use one of the tricks I thought up to shave down teamster_jr's version to 285 characters, so I wasn't going to claim the lead yet.

I flipped around the logic in the main conditional and shaved it down to 283 characters (I thought) and figured that would do it. But instead of playing the game of life, the gameboard instantly converged on the sierpinski gasket. That's right - instead of creating a shorter version of the game of life, I'd accidentally created a fractal generator.

I went through and ripped out all the unnecessary game of life stuff from it (looping, timers, random seeding of cells, etc.) and the result is a pure ascii output of the sierpinski gasket. I also re-formatted it to be somewhat easier to read, but remember, this is the result of golfing and obfuscation, so it still won't be that easy to read.

my $s = 150; @a = 0..$s; for $r (@a) { $b[$r][$_] = $" for @a } { for $r (@a) { for (@a) { $h = 0; for $i ($r-1..$r+1) { for $j ($_-1..$_+1) { $h++ if $b[$i][$j] ne $" & $i >= 0 & $i <= $s & $j >= 0 & $j <= $s & $i ^ $r & $j ^ $_ } } $e[$r][$_] = $h == 3 ? 0 : $b[$r][$_] ne $" & $h == 2 ? 0 : $" } } print map{ @{$e[$_]}, $/ } @a; }

I just think it's incredible that an incorrect application of DeMorgan's rules was all it took to turn the game of life into the sierpinski gasket. Stephen Wolfram would be proud of me. It sure made my day.


In reply to The accidental fractal by jimt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found