Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

The accidental fractal

by jimt (Chaplain)
on Sep 23, 2006 at 13:43 UTC ( #574513=obfuscated: 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.

Replies are listed 'Best First'.
Re: The accidental fractal
by jwkrahn (Monsignor) on Sep 23, 2006 at 21:14 UTC
    You can shorten this:
    for $r (@a) { $b[$r][$_] = $" for @a }
    To this:
    @b = ([($")x@a])x@a;
    You can also shorten this:
    print map{ @{$e[$_]}, $/ } @a;
    using the for statment modifier:
    print @{$e[$_]}, $/ for @a;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://574513]
Approved by davidrw
[ambrus]: you already have blackboards and a canvas for projector or overhead transparencies (or positive film slide projector, not used for maths) canvas in the same lecture halls today, and switch in a few minutes between presentations,
[ambrus]: they're only difficult to use together.
[ambrus]: overhead transparencies are a nice convenience by the way that mix the two slides, because you can write them in advance and edit them during the presentation easily. but they're not very much in fasion these days.
[ambrus]: you can even print them.
[Discipulus]: ambrus i'm trying out MremoteNG which wrap putty and rdp and many other things..
[Corion]: ambrus: Yes, ideally you would have the ease of overhead projection transparencies and pens drawing on them, combined with the computer generated slide text...
[Corion]: Maybe the solution would be a tablet (with pens), like the Wacom tablets, but you still need good software and need to know how to operate it well in an interactive setting ;)

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (11)
As of 2017-09-26 10:30 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (293 votes). Check out past polls.