Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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; }

Replies are listed 'Best First'.
(tye)Re: Sierpinskij (Re: Binomial Expansion)
by tye (Sage) 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?

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2023-12-06 15:20 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (30 votes). Check out past polls.