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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#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> > possibilitiesUsed;
vector< vector<int> >::iterator row;
vector<int>::iterator col;
int jKeeper[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int cubes[15][6] = { {4,6,2,0,0,0}, {1,3,7,0,0,0}, {2,4,8,0,0,0}, {1,3,5,0,0,0},
{4,6,8,0,0,0}, {1,5,7,0,0,0}, {2,6,8,0,0,0}, {3,5,7,9,10,11}, {8,12,15,0,0,0},
{8,13,15,0,0,0}, {8,12,13,0,0,0}, {9,11,14,0,0,0}, {10,11,14,0,0,0},
{12,13,15,0,0,0}, {9,10,14,0,0,0} };
int counterSet, i, j=0, temp, temp2, counter, sizeOfVec, depth=0;
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;
}
}
int routeCheck2(int a, int b)
{
//
//
if(!possibilitiesUsed.empty())
{
//
for(i=0; i< (int)possibilitiesUsed.size(); i++)
{
//
if(((possibilitiesUsed[i][0] == a) && (possibilitiesUsed[i][1] == b))
|| ((possibilitiesUsed[i][0] == b) && (possibilitiesUsed[i][1] == a)))
{
//
return 0;
}
}
return 1;
}
else
{
//
return 1;
}
}
void routeKeeper(int a, int b)
{
//
possibilities.push_back({a,b});
}
void createRouteMap(int start, int end)
{
//
//temp = j;
//
for(j=0; j<6; j++)
{
jKeeper[depth] = 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;
//possibilitiesUsed.push_back({start, cubes[start-1][j]});
depth+=1;
createRouteMap(cubes[start-1][j], end);
depth-=1;
j=jKeeper[depth];
possibilities.erase(possibilities.end());
}
}
//possibilitiesUsed.clear();
}
int main(int argc, char** argv) {
counter = 0;
createRouteMap(1, 15);
cout<< counter << endl;
system("pause");
return 0;
}
|