Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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)


Replies are listed 'Best First'.
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 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 (Chancellor) on Aug 17, 2002 at 06:38 UTC

    Nice one! I shaped your code like a triangle.

    #!/usr/bin/perl /\ /=~( '(?{'. ('`'|'%' ).('['^'-' ).('`'|'!'). ('`'|',').'"'. '\\$-=!\\$%|!\\' .'$%<<('.('['^'+') .('`'|'/').('['^'+') .'||'.('^'^('`'|'*')). ');'.('['^'+').('['^')') .('`'|')').('`'|'.').('['^ '/').'(\\$\\"'.('['^'#').''. '\\$-,('.('`'|'-').('`'|'!').( '['^'+').'\\$_?'."'".'/\\\\\\\\' ."'".':\\$\\".\\$\\",\\@;),\\$/),' .'\\@;=(!\\$%,'.('`'|'-').('`'|'!'). ('['^'+').'\\$;[\\$_]^\\$;[-\\$_],!\\' .'$%..\\@;)'.('['^',').('`'|'(').(('`')| ')').('`'|',').('`'|'%').'\\$---"})');'\+'
Re: Sierpinski Triangle
by Rudif (Hermit) on Aug 10, 2002 at 21:37 UTC
    And here is a default-supplying line, to prepend to it.
Re: Sierpinski Triangle
by eyepopslikeamosquito (Chancellor) 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 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 (Chancellor) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://188405]
Approved by TStanley
Front-paged by jarich
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-08-17 16:13 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (290 votes). Check out past polls.