clang-format and clang-tidy fixes for 4827805a

This commit is contained in:
github-actions 2021-06-28 12:16:14 +00:00
parent e21e53f2a0
commit 20560dc947

View File

@ -28,21 +28,21 @@ namespace Subsets {
*/ */
std::uint64_t subset_sum(int sum, const std::vector<int> &in_arr) { std::uint64_t subset_sum(int sum, const std::vector<int> &in_arr) {
int nelement = in_arr.size(); //number of subset element int nelement = in_arr.size(); // number of subset element
int count_of_subset = 0; int count_of_subset = 0;
for (int i=0; i < (1 << (nelement)); i++) { for (int i = 0; i < (1 << (nelement)); i++) {
std::vector<int> subset; std::vector<int> subset;
for ( int j=0 ; j < nelement ; j++) { for (int j = 0; j < nelement; j++) {
if (i & (1<<j)) { if (i & (1 << j)) {
subset.push_back(in_arr[j]); subset.push_back(in_arr[j]);
} }
} }
int check=0; int check = 0;
for ( int k=0 ; k < subset.size(); k++) { for (int k : subset) {
check += subset[k]; check += k;
} }
if (check==sum) { if (check == sum) {
count_of_subset++; count_of_subset++;
} }
} }
@ -58,30 +58,37 @@ std::uint64_t subset_sum(int sum, const std::vector<int> &in_arr) {
static void test() { static void test() {
// Test 1 // Test 1
std::cout << "1st test "; std::cout << "1st test ";
std::vector<int> array1 = {-7,-3,-2,5,8}; // input array std::vector<int> array1 = {-7, -3, -2, 5, 8}; // input array
assert(backtracking::Subsets::subset_sum(0,array1)==2); // first argument in subset_sum function is the required sum and second is the input array assert(backtracking::Subsets::subset_sum(0, array1) ==
2); // first argument in subset_sum function is the required sum and
// second is the input array
std::cout << "passed" << std::endl; std::cout << "passed" << std::endl;
// Test 2 // Test 2
std::cout << "2nd test "; std::cout << "2nd test ";
std::vector<int> array2 = {1, 2, 3, 3}; // input array std::vector<int> array2 = {1, 2, 3, 3}; // input array
assert(backtracking::Subsets::subset_sum(6,array2)==3); // first argument in subset_sum function is the required sum and second is the input array assert(backtracking::Subsets::subset_sum(6, array2) ==
3); // first argument in subset_sum function is the required sum and
// second is the input array
std::cout << "passed" << std::endl; std::cout << "passed" << std::endl;
// Test 3 // Test 3
std::cout << "3rd test "; std::cout << "3rd test ";
std::vector<int> array3 = {1, 1, 1, 1}; // input array std::vector<int> array3 = {1, 1, 1, 1}; // input array
assert(backtracking::Subsets::subset_sum(1,array3)==4); // first argument in subset_sum function is the required sum and second is the input array assert(backtracking::Subsets::subset_sum(1, array3) ==
4); // first argument in subset_sum function is the required sum and
// second is the input array
std::cout << "passed" << std::endl; std::cout << "passed" << std::endl;
// Test 4 // Test 4
std::cout << "4th test "; std::cout << "4th test ";
std::vector<int> array4 = { 3, 3, 3, 3 }; // input array std::vector<int> array4 = {3, 3, 3, 3}; // input array
assert(backtracking::Subsets::subset_sum(6,array4)==6); // first argument in subset_sum function is the required sum and second is the input array assert(backtracking::Subsets::subset_sum(6, array4) ==
6); // first argument in subset_sum function is the required sum and
// second is the input array
std::cout << "passed" << std::endl; std::cout << "passed" << std::endl;
} }
/** /**
* @brief Main function * @brief Main function
* @returns 0 on exit * @returns 0 on exit