Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of derangement/subfactorial with iterative implementation #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Commits on Dec 10, 2023

  1. Improve performance of derangement/subfactorial with iterative im…

    …plementation
    
    Use the recursive formula
      !n = (n-1) * (!(n-1) + !(n-2))
    presented here: https://en.wikipedia.org/wiki/Derangement#Counting_derangements
    FedericoStra committed Dec 10, 2023
    Configuration menu
    Copy the full SHA
    53c5e71 View commit details
    Browse the repository at this point in the history

Commits on Dec 13, 2023

  1. Improve performance of derangement/subfactorial with simpler recu…

    …rsive formula and inplace computations
    
    Use the simpler formula
    
    !n = n * !(n-1) + (-1)^n
    
    and use inplace operations on `BigInt`s to avoid allocations.
    FedericoStra committed Dec 13, 2023
    Configuration menu
    Copy the full SHA
    afc071d View commit details
    Browse the repository at this point in the history