??? Strange. I copied and pasted from a web site.

function productRange(a,b) {
  var product=a,i=a;

  while (i++<b) {
    product*=i;
  }
  return product;
}

function combinations(n,k) {
  if (n==k) {
    return 1;
  } else {
    k=Math.max(k,n-k);
    return productRange(k+1,n)/productRange(1,n-k);
  }
}

function distributions(N, M) {
  return  combinations( N+M-1,M);
}

Maybe I should not trust everything I read. However, I can't immediately see
any bugs in the above code....
Aha! Now I see! It's wrong when k = 0, I'll fix it. Hang on.

May be a bad fix, but I think it works better now.

-Øystein


2010/5/28 Massimiliano Maini <[email protected]>

> Now it works.
>
> Your combinations function seems to be wrong for m=0:
>
> combin(24,0) = 1
> combinations(24,0) = 25
>
> Guess you just have to define distribution as a function of COMBIN ...
>
> MaX.
>
> 2010/5/28 Øystein Johansen <[email protected]>:
> > 2010/5/28 Massimiliano Maini <[email protected]>
> >>
> >> Google docs, right .. excel is so has been :)
> >>
> >> BTW, your link does not work.
> >
> > I see .... I'll try to publish it as a web page:
> >
> >
> http://spreadsheets.google.com/pub?key=tqUcK-zFdgQC_byUJvbgqvQ&output=html
> >
> > -Øystein
> >
> >
>
_______________________________________________
Bug-gnubg mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-gnubg

Reply via email to