SimiLie
Loading...
Searching...
No Matches
binomial_coefficient.hpp
1
// SPDX-FileCopyrightText: 2024 Baptiste Legouix
2
// SPDX-License-Identifier: MIT
3
4
#pragma once
5
6
#include <ddc/ddc.hpp>
7
8
namespace
sil
{
9
10
namespace
misc {
11
12
// From https://stackoverflow.com/a/44719219
13
constexpr
inline
std::size_t
binomial_coefficient
(std::size_t n, std::size_t k)
noexcept
14
{
15
return
(k > n) ? 0 :
// out of range
16
(k == 0 || k == n) ? 1
17
:
// edge
18
(k == 1 || k == n - 1) ? n
19
:
// first
20
binomial_coefficient
(n - 1, k - 1) * n / k;
// recursive
21
}
22
23
}
// namespace misc
24
25
}
// namespace sil
sil::misc::binomial_coefficient
constexpr std::size_t binomial_coefficient(std::size_t n, std::size_t k) noexcept
Definition
binomial_coefficient.hpp:13
sil
The top-level namespace of SimiLie.
Definition
csr.hpp:14
include
similie
misc
binomial_coefficient.hpp
Generated by
1.12.0