Skip to content

Commit 9ad083d

Browse files
committed
fix: remove p from the argument list of NCRModuloP::ncr
1 parent 57bf4c0 commit 9ad083d

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

math/ncr_modulo_p.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class NCRModuloP {
8989
* @params[in] the numbers 'n', 'r' and 'p'
9090
* @returns the value nCr % p
9191
*/
92-
int64_t ncr(const uint64_t& n, const uint64_t& r, const uint64_t& p) {
92+
int64_t ncr(const uint64_t& n, const uint64_t& r) {
9393
// Base cases
9494
if (r > n) {
9595
return 0;
@@ -121,13 +121,19 @@ class NCRModuloP {
121121
* ncr function
122122
* @returns void
123123
*/
124-
static void tests(math::ncr_modulo_p::NCRModuloP ncrObj) {
124+
static void tests() {
125125
// (52323 C 26161) % (1e9 + 7) = 224944353
126-
assert(ncrObj.ncr(52323, 26161, 1000000007) == 224944353);
126+
assert(
127+
math::ncr_modulo_p::NCRModuloP(60000, 1000000007).ncr(52323, 26161) ==
128+
224944353);
127129
// 6 C 2 = 30, 30%5 = 0
128-
assert(ncrObj.ncr(6, 2, 5) == 0);
130+
assert(math::ncr_modulo_p::NCRModuloP(20, 5).ncr(6, 2) == 0);
129131
// 7C3 = 35, 35 % 29 = 8
130-
assert(ncrObj.ncr(7, 3, 29) == 6);
132+
assert(math::ncr_modulo_p::NCRModuloP(100, 29).ncr(7, 3) == 6);
133+
}
134+
135+
void other_tests() {
136+
assert(math::ncr_modulo_p::NCRModuloP(1000, 13).ncr(10, 3) == 120 % 13);
131137
}
132138

133139
/**
@@ -142,9 +148,10 @@ int main() {
142148
math::ncr_modulo_p::NCRModuloP(size, p);
143149
// test 6Ci for i=0 to 7
144150
for (int i = 0; i <= 7; i++) {
145-
std::cout << 6 << "C" << i << " = " << ncrObj.ncr(6, i, p) << "\n";
151+
std::cout << 6 << "C" << i << " = " << ncrObj.ncr(6, i) << "\n";
146152
}
147-
tests(ncrObj); // execute the tests
153+
tests(); // execute the tests
154+
other_tests();
148155
std::cout << "Assertions passed\n";
149156
return 0;
150157
}

0 commit comments

Comments
 (0)