Created
November 10, 2022 10:23
-
-
Save robertodr/5bb9d77799257ac2ac2f048eb7dd148f to your computer and use it in GitHub Desktop.
Some constexpr stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace detail { | |
constexpr auto factorial(size_t n) -> size_t { | |
return n <= 1 ? 1 : (n * factorial(n - 1)); | |
} | |
constexpr auto binomial(size_t n, size_t k) -> size_t { | |
if (n == k || k == 0) { | |
return 1; | |
} else { | |
if (n == 0) { | |
return 0; | |
} else { | |
return binomial(n - 1, k - 1) + binomial(n - 1, k); | |
} | |
} | |
} | |
constexpr auto multiset_coefficient(size_t n, size_t k) -> size_t { | |
return binomial(n + k - 1, n); | |
} | |
} // namespace detail | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment