Last active
February 19, 2016 12:25
-
-
Save kuniyoshi/8a784c36012f9dd30725 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int get_size(int depth) | |
{ | |
int r = 0; | |
switch (depth) | |
{ | |
case 0: r = 2; break; | |
case 1: r = 2; break; | |
case 2: r = 3; break; | |
} | |
return r; | |
} | |
void fill_until(vector< string >* v, int depth) | |
{ | |
vector< int > depths; | |
depths.reserve(depth); | |
for (int i = 0; i < depth; ++i) | |
{ | |
depths.push_back(get_size(i)); | |
} | |
vector< int > positions; | |
positions.reserve(depth); | |
positions.push_back(1); | |
int base = 1; | |
for (int i = 0; i < depth; ++i) | |
{ | |
base = base * get_size(i); | |
positions.push_back(base); | |
} | |
vector< int > current; | |
current.reserve(depth); | |
for (int i = 0; i < depth; ++i) | |
{ | |
current.push_back(0); | |
} | |
for (int i = 0; i < positions[positions.size() - 1]; ++i) | |
{ | |
for (int j = 0; j < depth; ++j) | |
{ | |
current[j] = (i / positions[j]) % depths[j]; | |
} | |
ostringstream oss; | |
for (int j = 0; j < depth; ++j) | |
{ | |
oss << current[j]; | |
oss << ", "; | |
} | |
v->push_back(oss.str()); | |
} | |
} | |
int main() | |
{ | |
const int depth = 3; | |
vector< string > v; | |
fill_until(&v, depth); | |
for (vector< string >::iterator it = v.begin(); it != v.end(); ++it) | |
{ | |
cerr << *it << endl; | |
} | |
} |
Author
kuniyoshi
commented
Feb 19, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment