Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (11)
    As of 2014-09-17 18:08 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (93 votes), past polls