Hello,

I don't know if this is the appropriate place to submit code, but...

The combinat.py file lists Rencontres numbers in the TODO section.
Here's a function that implements Rencontres numbers. I tried to copy
the documentation style, but feel free to edit as necessary.


def rencontres(n, k):
    r"""
    Returns the Rencontres number D(n,k), the number of permutations of
    {1, 2,..., n} with k fixed points.

    EXAMPLES:
    Because 312 and 231 are the two permutations of {1, 2, 3} with 0 fixed
    points, we have:

        sage: rencontres(3,0)
        2

    Also:

        sage: rencontres(6,1)
        264

    REFERENCES:

    http://en.wikipedia.org/wiki/Rencontres_number

    Sequence A008290 in the OEIS.
    """
    if (n - k) % 2 == 0:
        return binomial(n, k) * ceil(factorial(n - k)/e)
    else:
        return binomial(n, k) * floor(factorial(n - k)/e)


-- 
---  Dan Drake <[EMAIL PROTECTED]>
-----  KAIST Department of Mathematical Sciences
-------  http://math.kaist.ac.kr/~drake

Attachment: signature.asc
Description: Digital signature

Reply via email to