I am trying to learn C ++ and trying to solve a problem in which there are several steps and the number of possible ways that you can go up in steps, give all the permutations of the possible ways that you can go up in a step, For example, if there are 5 steps to go up , and I can either move 1 step at a time, 2 steps at a time or 3 steps at a time, I would need to print all permutations 1, 2 and 3, which add up to 5: [1, 1, 1, 1, 1] , [1, 1, 1, 2] , ....
I started with this code (it's not done yet), but I get this error:
Undefined symbols for architecture x86_64: "_num_steps(int, std::__1::vector<int, std::__1::allocator<int> >, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >, std::__1::vector<std::__1::vector<int, std::__1::allocator<int> >, std::__1::allocator<std::__1::vector<int, std::__1::allocator<int> > > >)", referenced from: num_steps(int, std::__1::vector<int, std::__1::allocator<int> >) in num_steps-FTVSiK.o ld: symbol(s) not found for architecture x86_64
I really don't understand what I'm doing wrong. I would appreciate it if I could help. Thanks!
#include <iostream> #include <vector> #include <string> #include <cmath> using namespace std; //prototypes void _num_steps(int amount, vector<int> possible_steps, vector<vector<int>> steps_list, vector<vector<int>> result); int sum(vector<int> steps_list); void num_steps(int amount, vector<int> possible_steps); // // // void num_steps(int amount, vector<int> possible_steps) { vector<vector<int>> result; _num_steps(amount, possible_steps, {{}}, result); //print_result(result); } int sum(vector<int> steps_list) { int sum_of_steps(0); for (auto step: steps_list) { sum_of_steps += step; } return sum_of_steps; } void _num_steps(int amount, vector<int> possible_steps, vector<int> steps_list, vector<vector<int>> result) { if (sum(steps_list) == amount) { result.push_back(steps_list); return; } else if (sum(steps_list) >= amount) { return; } for (auto steps: possible_steps) { auto steps_list_copy = steps_list; steps_list_copy.push_back(steps); _num_steps(amount, possible_steps, steps_list_copy, result); } cout << "yeah" << endl; return; } int main(int argc, char* argv[]) { num_steps(5, {1, 2, 3}); return 0; }