diff options
| author | boblied <boblied@gmail.com> | 2023-01-29 10:31:03 -0600 |
|---|---|---|
| committer | boblied <boblied@gmail.com> | 2023-01-29 10:31:03 -0600 |
| commit | c8c63d4d6650d0fde10e7b76f3b3177eae16c1f1 (patch) | |
| tree | 04c0dfe0619c6d8f37c385dbcfa921807452a83c /challenge-201/deadmarshal/cpp/ch-2.cpp | |
| parent | f8a32b4ca7a9d3974a900224af1bdb0309cf8142 (diff) | |
| parent | 18f57b402d576194dd58876a3a81f82330935e24 (diff) | |
| download | perlweeklychallenge-club-c8c63d4d6650d0fde10e7b76f3b3177eae16c1f1.tar.gz perlweeklychallenge-club-c8c63d4d6650d0fde10e7b76f3b3177eae16c1f1.tar.bz2 perlweeklychallenge-club-c8c63d4d6650d0fde10e7b76f3b3177eae16c1f1.zip | |
Merge branch 'master' into w184
Diffstat (limited to 'challenge-201/deadmarshal/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-201/deadmarshal/cpp/ch-2.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-201/deadmarshal/cpp/ch-2.cpp b/challenge-201/deadmarshal/cpp/ch-2.cpp new file mode 100644 index 0000000000..d05bc157e5 --- /dev/null +++ b/challenge-201/deadmarshal/cpp/ch-2.cpp @@ -0,0 +1,31 @@ +#include<iostream> + +#define N 5 +static int count{}; + +void find_combinations(int *arr, + int index, + int num, + int reduced_num) +{ + if(reduced_num < 0) return; + if(reduced_num == 0) + { + count++; + return; + } + int prev = index == 0 ? 1 : arr[index-1]; + for(int i = prev; i <= num; ++i) + { + arr[index] = i; + find_combinations(arr,index+1,num,reduced_num-i); + } +} + +int main() +{ + int arr[N]; + find_combinations(arr,0,N,N); + std::cout << count << '\n'; +} + |
