Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Sierpinski Triangle

by MrNobo1024 (Hermit)
on Aug 07, 2002 at 17:46 UTC ( #188405=obfuscated: print w/ replies, xml ) Need Help??

$}=1|1<<pop;print($"x$},(map$_?$=:$"x2,@;), $/),@;=(1,map$;[$_]^$;[-$_],1..@;)while$}--
This little program draws the sierpinski triangle fractal. Specify the size on the command line (should be about 5 depending on your screen size)

--MrNobo1024
s]]HrLfbfe|EbBibmv]e|s}w}ciZx^RYhL}e^print

Comment on Sierpinski Triangle
Download Code
Re: Sierpinski Triangle
by Len (Friar) on Aug 08, 2002 at 08:15 UTC
    MrNobo1024++ for this math magic !

    If you feel inspired by this kind of geometric stuff, check out The Geometry Junkyard for a huge collection of geometrical and recreational math.

Re: Sierpinski Triangle
by Rudif (Hermit) on Aug 10, 2002 at 21:37 UTC
    Neat.
    And here is a default-supplying line, to prepend to it.
    @ARGV||push@ARGV,5;
    Rudif
Re: Sierpinski Triangle
by hossman (Prior) on Aug 12, 2002 at 06:39 UTC
    Very cool... but i made two tweaks, one is a simplified version of Rudif's default suggestion, and the other changes the text to something more triangle-ish (i don't think it significantly reduces the obfuscation)

    $}=1|1<<(pop||3);print($"x$},(map$_?'/\\':$"x2, @;),$/),@;=(1,map$;[$_]^$;[-$_],1..@;)while$}--
Re: Sierpinski Triangle
by eyepopslikeamosquito (Canon) on Aug 17, 2002 at 06:38 UTC

    Nice one! I shaped your code like a triangle.

    #!/usr/bin/perl /\ /=~( '(?{'. ('`'|'%' ).('['^'-' ).('`'|'!'). ('`'|',').'"'. '\\$-=!\\$%|!\\' .'$%<<('.('['^'+') .('`'|'/').('['^'+') .'||'.('^'^('`'|'*')). ');'.('['^'+').('['^')') .('`'|')').('`'|'.').('['^ '/').'(\\$\\"'.('['^'#').''. '\\$-,('.('`'|'-').('`'|'!').( '['^'+').'\\$_?'."'".'/\\\\\\\\' ."'".':\\$\\".\\$\\",\\@;),\\$/),' .'\\@;=(!\\$%,'.('`'|'-').('`'|'!'). ('['^'+').'\\$;[\\$_]^\\$;[-\\$_],!\\' .'$%..\\@;)'.('['^',').('`'|'(').(('`')| ')').('`'|',').('`'|'%').'\\$---"})');'\+'
Re: Sierpinski Triangle
by eyepopslikeamosquito (Canon) on Aug 17, 2002 at 16:16 UTC

    Here is an alternative solution. This one is a little shorter and strict and warning safe. Also it does not emit an empty first line. I developed it from ideas in previous solutions posted to fwp@perl.org. See golf thread. If the alien golfers take up my challenge, it will be significantly shortened.

    $_=$"x((1|1<<(pop||4))-1)."/\\ ";print,s,(?<=\\)..,$&^"\017|",ge,s,$,/\\,while+s+^ ++

      Update: The golf dream team of Ton Hospel, Eugene van der Pijll, Mtv Europe and Keith C Ivey whittled 15 strokes from my initial offering:

      #!perl -l $_=$"x2**(pop||4);s'$'/\\',print,s/(?<=\\)../$&^aD^n8/egwhile+s\^ \\

      Here are some other solutions (without default argument) they concocted during their fidgeting:

      $_=$"x(1<<pop);print,s/(?<=\\)../$&^"\17|"/egwhile+s^\n?$^/\\\n^,s\^ \ +\ $_=$"x(1<<pop).$/;print,s/(?<=\\)../$&^"\17|"/egwhile+s^$^/\\^,s\^ \\ -lX $_=$"x2**pop;print,s/(?<=\\)../$&^"\17|"/egwhile+s*$*/\\**s+^ ++ -lX $_=$"x2**pop;print,s/(?<=\\)../$&^"\17|"/egwhile+s-^ (.*)-$+/\\- -l $_=$"x2**pop;s'$'/\\',print,s/(?<=\\)../$&^"\17|"/egwhile+s\^ \\ -l $_=$"x2**pop;s'$'/\\',print,s/(?<=\\)../$&^aD^n8/egwhile+s\^ \\
Re: Sierpinski Triangle
by eyepopslikeamosquito (Canon) on Aug 21, 2002 at 12:36 UTC

    Still going! Though not shortest, I find this one amusing for some reason. Oh, and I have given it a name: "five substitutions".

    #!perl -l s--$"x$^F**pop-e,s-.-s,,,,s,$,/\\,,print,s,(?<=/.)..,$&^h9^gE,ge-ge

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://188405]
Approved by TStanley
Front-paged by jarich
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (10)
As of 2014-09-01 07:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (299 votes), past polls