Skip to content

Commit aa83739

Browse files
github-actionsgithub-actions
authored andcommitted
clang-format and clang-tidy fixes for f30cb37
1 parent 60f2e23 commit aa83739

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

math/n_bonacci.cpp

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @file
3-
* @brief Implementation of the [N-bonacci](http://oeis.org/wiki/N-bonacci_numbers) series
3+
* @brief Implementation of the
4+
* [N-bonacci](http://oeis.org/wiki/N-bonacci_numbers) series
45
*
56
* @details
67
* In general, in N-bonacci sequence,
@@ -30,18 +31,22 @@ namespace math {
3031
*/
3132
namespace n_bonacci {
3233
/**
33-
* @brief Finds the N-Bonacci series for the `n` parameter value and `m` parameter terms
34+
* @brief Finds the N-Bonacci series for the `n` parameter value and `m`
35+
* parameter terms
3436
* @param n is in the N-Bonacci series
3537
* @param m is the number of terms in the N-Bonacci sequence
3638
* @returns the n-bonacci sequence as vector array
3739
*/
3840
std::vector<int> N_bonacci(int n, unsigned int m) {
3941
std::vector<int> a(m, 0); // we create an empty array of size m
4042

41-
a[n - 1] = 1; /// we initialise the (n-1)th term as 1 which is the sum of preceding N zeros
42-
a[n] = 1; /// similarily the sum of preceding N zeros and the (N+1)th 1 is also 1
43+
a[n - 1] = 1; /// we initialise the (n-1)th term as 1 which is the sum of
44+
/// preceding N zeros
45+
a[n] = 1; /// similarily the sum of preceding N zeros and the (N+1)th 1 is
46+
/// also 1
4347
for (int i = n + 1; i < m; i++) {
44-
// this is an optimized solution that works in O(M) time and takes O(M) extra space here we use the concept of the sliding window the current
48+
// this is an optimized solution that works in O(M) time and takes O(M)
49+
// extra space here we use the concept of the sliding window the current
4550
// term can be computed using the given formula
4651
a[i] = 2 * a[i - 1] - a[i - 1 - n];
4752
}
@@ -57,32 +62,51 @@ std::vector<int> N_bonacci(int n, unsigned int m) {
5762
static void test() {
5863
// n = 1 m = 1 return [1, 1]
5964
std::cout << "1st test";
60-
std::vector<int> arr1 = math::n_bonacci::N_bonacci(1, 1); // first input is the param n and second one is the param m for N-bonacci func
61-
std::vector<int> output_array1 = {1, 1}; // It is the expected output series of length m
65+
std::vector<int> arr1 = math::n_bonacci::N_bonacci(
66+
1, 1); // first input is the param n and second one is the param m for
67+
// N-bonacci func
68+
std::vector<int> output_array1 = {
69+
1, 1}; // It is the expected output series of length m
6270
assert(std::equal(std::begin(arr1), std::end(arr1),
6371
std::begin(output_array1)));
6472
std::cout << "passed" << std::endl;
6573

66-
// n = 5 m = 15 return [0, 0, 0, 0, 1, 1, 2, 4, 8, 16, 31, 61, 120, 236, 464]
74+
// n = 5 m = 15 return [0, 0, 0, 0, 1, 1, 2, 4, 8, 16, 31, 61, 120, 236,
75+
// 464]
6776
std::cout << "2nd test";
68-
std::vector<int> arr2 = math::n_bonacci::N_bonacci(5, 15); // first input is the param n and second one is the param m for N-bonacci func
69-
std::vector<int> output_array2 = {0, 0, 0, 0, 1, 1, 2, 4, 8, 16, 31, 61, 120, 236, 464}; // It is the expected output series of length m
77+
std::vector<int> arr2 = math::n_bonacci::N_bonacci(
78+
5, 15); // first input is the param n and second one is the param m for
79+
// N-bonacci func
80+
std::vector<int> output_array2 = {
81+
0, 0, 0, 0, 1, 1, 2, 4,
82+
8, 16, 31, 61, 120, 236, 464}; // It is the expected output series of
83+
// length m
7084
assert(std::equal(std::begin(arr2), std::end(arr2),
7185
std::begin(output_array2)));
7286
std::cout << "passed" << std::endl;
7387

74-
// n = 6 m = 17 return [0, 0, 0, 0, 0, 1, 1, 2, 4, 8, 16, 32, 63, 125, 248, 492, 976]
88+
// n = 6 m = 17 return [0, 0, 0, 0, 0, 1, 1, 2, 4, 8, 16, 32, 63, 125, 248,
89+
// 492, 976]
7590
std::cout << "3rd test";
76-
std::vector<int> arr3 = math::n_bonacci::N_bonacci(6, 17); // first input is the param n and second one is the param m for N-bonacci func
77-
std::vector<int> output_array3 = {0, 0, 0, 0, 0, 1, 1, 2, 4, 8, 16, 32, 63, 125, 248, 492, 976}; // It is the expected output series of length m
91+
std::vector<int> arr3 = math::n_bonacci::N_bonacci(
92+
6, 17); // first input is the param n and second one is the param m for
93+
// N-bonacci func
94+
std::vector<int> output_array3 = {
95+
0, 0, 0, 0, 0, 1, 1, 2, 4,
96+
8, 16, 32, 63, 125, 248, 492, 976}; // It is the expected output series
97+
// of length m
7898
assert(std::equal(std::begin(arr3), std::end(arr3),
7999
std::begin(output_array3)));
80100
std::cout << "passed" << std::endl;
81101

82102
// n = 56 m = 15 return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
83103
std::cout << "4th test";
84-
std::vector<int> arr4 = math::n_bonacci::N_bonacci(56, 15); // first input is the param n and second one is the param m for N-bonacci func
85-
std::vector<int> output_array4 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; // It is the expected output series of length m
104+
std::vector<int> arr4 = math::n_bonacci::N_bonacci(
105+
56, 15); // first input is the param n and second one is the param m
106+
// for N-bonacci func
107+
std::vector<int> output_array4 = {
108+
0, 0, 0, 0, 0, 0, 0, 0,
109+
0, 0, 0, 0, 0, 0, 0}; // It is the expected output series of length m
86110
assert(std::equal(std::begin(arr4), std::end(arr4),
87111
std::begin(output_array4)));
88112
std::cout << "passed" << std::endl;

0 commit comments

Comments
 (0)