#include <iostream> #include <vector> using namespace std; /* functions that gets passed two "ints" x and y and then returns a vector of vectors showing all the different combinations of chosing x items from y. This would then be called multiple times to generate indexes used for fatorisation. Think about actually creating lists or something that could be created by the call - but this is OK for the time being */ /* combos passes integers from and total and returns a vector of vectors of all combos */ vector< vector<unsigned int> > combos(unsigned int, unsigned int); int main() { //create a vector of vectors that contain ints vector < vector<unsigned int> > combinations = combos (10,10); for (unsigned int i = 0; i != combinations.size(); i++){ unsigned int com_length = combinations[i].size(); cout << "length of vector " << com_length << endl; for(unsigned int j = 0; j != com_length; j++){ cout << combinations[i][j]; } cout << endl; } return 0; } vector< vector<unsigned int> > combos(unsigned int from, unsigned int total){ vector< vector<unsigned int> > vec; for (unsigned int i = 1; i != total; i++){ vector <unsigned int> temp; //create temp new each time so you get rid of old one and start with a blank for (unsigned int j = 1; j != i; j++){ temp.push_back(j); } vec.push_back(temp); } return vec; }
Sunday, December 8, 2013
Amicable numbers part 0
Working on this but need a reference copy to see while I am away from home. This lists up all combinations of x from y in order to work out amicable numbers.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment