Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Pathologically Eclectic Rubbish Lister
 
PerlMonks

Sierpinski Triangle

by MrNobo1024 (Hermit)
 | Log in | Create a new user | The Monastery Gates | Super Search | 
 | Seekers of Perl Wisdom | Meditations | PerlMonks Discussion | 
 | Obfuscation | Reviews | Cool Uses For Perl | Perl News | Q&A | Tutorials | 
 | Poetry | Recent Threads | Newest Nodes | Donate | What's New | 

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.

[reply]
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
[reply]
[d/l]
Re: Sierpinski Triangle
by hossman (Parson) 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$}--
[reply]
[d/l]
Re: Sierpinski Triangle
by eyepopslikeamosquito (Abbot) on Aug 17, 2002 at 06:38 UTC

    Nice one! I shaped your code like a triangle.

    #!/usr/bin/perl /\ /=~( '(?{'. ('`'|'%' ).('['^'-' ).('`'|'!'). ('`'|',').'"'. '\\$-=!\\$%|!\\' .'$%<<('.('['^'+') .('`'|'/').('['^'+') .'||'.('^'^('`'|'*')). ');'.('['^'+').('['^')') .('`'|')').('`'|'.').('['^ '/').'(\\$\\"'.('['^'#').''. '\\$-,('.('`'|'-').('`'|'!').( '['^'+').'\\$_?'."'".'/\\\\\\\\' ."'".':\\$\\".\\$\\",\\@;),\\$/),' .'\\@;=(!\\$%,'.('`'|'-').('`'|'!'). ('['^'+').'\\$;[\\$_]^\\$;[-\\$_],!\\' .'$%..\\@;)'.('['^',').('`'|'(').(('`')| ')').('`'|',').('`'|'%').'\\$---"})');'\+'
[reply]
[d/l]
Re: Sierpinski Triangle
by eyepopslikeamosquito (Abbot) 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+^ ++
[reply]
[d/l]

      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\^ \\
[reply]
[d/l]
[select]
Re: Sierpinski Triangle
by eyepopslikeamosquito (Abbot) 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
[reply]
[d/l]

Back to Obfuscated Code

Login:
Password
remember me
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
Community Ads
Chatterbox
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users
Others musing on the Monastery: (9)
ikegami
planetscape
atcroft
herveus
thezip
Eyck
ssandv
llancet
gnosti
As of 2009-11-21 02:12 GMT
Sections
The Monastery Gates
Seekers of Perl Wisdom
Meditations
PerlMonks Discussion
Categorized Q&A
Tutorials
Obfuscated Code
Perl Poetry
Cool Uses for Perl
Perl News
Information
PerlMonks FAQ
Guide to the Monastery
What's New at PerlMonks
Voting/Experience System
Tutorials
Reviews
Library
Perl FAQs
Other Info Sources
Find Nodes
Nodes You Wrote
Super Search
List Nodes By Users
Newest Nodes
Recently Active Threads
Selected Best Nodes
Best Nodes
Worst Nodes
Saints in our Book
Leftovers
The St. Larry Wall Shrine
Offering Plate
Awards
Craft
Snippets Section
Code Catacombs
Quests
Editor Requests
Buy PerlMonks Gear
PerlMonks Merchandise
Planet Perl
Perlsphere
Use Perl
Perl.com
Perl 5 Wiki
Perl Jobs
Perl Mongers
Perl Directory
Perl documentation
CPAN
Random Node
Voting Booth

Future historians will find that the material characteristic of the current era is...

Aluminium
Plastic
Oil
Water
Carbon dioxide
Copper
Iron
Silicon
Salt
Uranium
Hydrogen
Other

Results (725 votes), past polls