Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I take great offense in calling my nCr function horribly inaccurate.

You do say right away that is a valid formula for binomial coefficients, but then you say it's hardly a good one?

It is a formula for calculating r-combinations, not binomial coefficients.

The formula for binomial expansion is:

(x+y)^n = \ C(n,j) * x^(n-j) *y^j

And btw, it is the definitive formula for calculating r-combinations. It's like saying 4/2 is not the same as 2. While 2 is a better way to write 4/2, not every one recognizes 2 right away, and I feel, for the benefit of the reader of me 'craft', n!/(r!(n-r)! is a better way to go.

As for your function, it is shorter, but a litle mysterious when it comes to the math.

               9!         9*8*7* 6!      9*8*7   504
 nCr(9,3) = ---------   = ----------- = ------ = --- = 84
            3!*(9-3)!     3*2*1*(6!)     3*2*1    6

 which follows from the fact that nCr(n,r) = nCr(n,n-r)

 n!              n!               n!         _    n!
------- = ----------------- = -------------  = ---------
r!(n-r)    (n-r)!(n-(n-r))!   (n-r)!(n-n+r)!   (n-r)!(r)!
This however only works for n>r, as long as n and r are both non-negative integers, but shouldn't be a problem in this case.

As for things being integer, since the input is an integer, it follows that any integer multiple of that integer, will also be an integer.

I give, I give, theory v. practice, there is a difference.

Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

In reply to (crazyinsomniac) Re: (2) Binomial Expansion by crazyinsomniac
in thread Binomial Expansion by crazyinsomniac

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (6)
    As of 2017-10-21 11:17 GMT
    Find Nodes?
      Voting Booth?
      My fridge is mostly full of:

      Results (269 votes). Check out past polls.