1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
#include <iostream>
#include <vector>
#include <cmath>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
/*
possibilities will keep the possible combinations, routes like {1,4}{4,8}{8,7} etc till it arrives to 15
*/
vector< vector<int> > possibilities;
vector< vector<int> >::iterator row;
vector<int>::iterator col;
int cubes[15][6] = { {2,3,5,0,0,0}, {1,4,6,0,0,0}, {1,4,7,0,0,0}, {2,3,8,0,0,0},
{1,6,7,0,0,0}, {2,5,8,0,0,0}, {3,5,8,0,0,0}, {4,6,7,9,10,13}, {8,11,12,0,0,0},
{8,11,14,0,0,0}, {9,10,15,0,0,0}, {9,13,15,0,0,0}, {8,12,14,0,0,0},
{10,13,15,0,0,0}, {11,12,14,0,0,0} };
int counterSet, i, j, temp, temp2, counter, sizeOfVec;
int routeCheck(int a, int b)
{
//
//
if(!possibilities.empty())
{
//
for(i=0; i< (int)possibilities.size(); i++)
{
//
if(((possibilities[i][0] == a) && (possibilities[i][1] == b)) ||
((possibilities[i][0] == b) && (possibilities[i][1] == a)))
{
//
return 0;
}
}
return 1;
}
else
{
//
return 1;
}
}
void routeKeeper(int a, int b)
{
//
if(routeCheck(a,b) == 1)
{
//
possibilities.push_back({a,b});
}
}
void createRouteMap(int start, int end)
{
//
temp = j;
for(j=0; j<6; j++)
{
if(cubes[start-1][j]==end) // if it is destination
{
//
counter+=1;
cout << "counter is: " << counter << endl;
j++;
}
else if( (routeCheck(start, cubes[start-1][j])==1) && (cubes[start-1][j] != end) &&
(cubes[start-1][j] != 0) )
{
//
routeKeeper(start, cubes[start-1][j]);
for(row = possibilities.begin() ; row != possibilities.end() ; row++)
{
//
for(col = row->begin(); col != row->end(); col++)
{
//
cout << *col << ",";
}
}
cout << endl;
createRouteMap(cubes[start-1][j], end);
possibilities.erase(possibilities.end());
}
}
j=temp;
}
int main(int argc, char** argv) {
counter = 0;
createRouteMap(1, 15);
cout<< counter << endl;
system("pause");
return 0;
}
|