Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Sierpinskij (Re: Binomial Expansion)

by larsen (Parson)
on Mar 29, 2001 at 13:48 UTC ( #68067=note: print w/ replies, xml ) Need Help??


in reply to Binomial Expansion

A pattern? Yes, of course!
Here what you can obtain if you paint a Pascal Triangle.

Update I think this link could be amusing: Pascal's Triangle

#!/usr/bin/perl use strict; my $n = 10; for my $i (0 .. $n) { for my $j (0 .. $i) { my $coefficient = nCr($i, $j); if ($coefficient % 2) { print '#'; } else { print ' '; } } print "\n"; } # returns n!/r!(n-r)! sub nCr { my $n=shift; my $r=shift; return int nFactorial($n) / int nFactorial($r) * int nFactorial($n +-$r); } # like the name says, n! sub nFactorial { my $n=shift; my $product = 1; while($n>0) { $product *= $n--; } return $product; }


Comment on Sierpinskij (Re: Binomial Expansion)
Download Code
Replies are listed 'Best First'.
(tye)Re: Sierpinskij (Re: Binomial Expansion)
by tye (Cardinal) on Mar 29, 2001 at 21:13 UTC

    I thought part of the point of Pascal's triangle was to show that you don't have to compute factorials:

    my @line= (1); while( 1 ) { print "@line\n"; push @line, 0; for( reverse 1..$#line ) { $line[$_] += $line[$_-1]; } }
    Be sure to pipe the output to more.

            - tye (but my friends call me "Tye")
Re: Sierpinskij (Re: Binomial Expansion)
by rpc (Monk) on Mar 29, 2001 at 23:10 UTC
    Not only is it Pacal's triangle, it's also a Sirpinski Gasket if you associate one character/color to even numbers, and another to odd.

    Math rox.

    Update: Ugh i am not awake yet. Forgive my redundancy.

Re: Sierpinskij (Re: Binomial Expansion)
by oha (Friar) on Dec 19, 2003 at 20:05 UTC
    i found that code some times ago, unfortunately i don't know the author. i post here, maybe someone don't know.
    #!/usr/bin/perl -l s--@{[(gE^Ge)=~/[^g^e]/g]}[g^e]x((!!+~~g^e^g^e)<<pop).!gE-ge, s-[^ge^ge]-s,,,,s,@{[(g^';').(e^'?')]},(G^'/').(E^'|')^Ge,ge, print,s,(?<=/[^g^e])[^g^e][^g^e],$&^(G^'/').(E^'|')^gE,ge-ge

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://68067]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2015-07-31 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls