invert.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vector>
00003 
00004 int n = 100;
00005 
00006 int getLine(int index)
00007 {
00008         index = index % (2*n);
00009 
00010         if (index >= n)
00011                 return 2*n - 1 - 2*(index - n);
00012         else
00013                 return 2*index;
00014 }
00015 
00016 int getIndex(int line)
00017 {
00018         if (line % 2 == 0)
00019                 return line / 2;
00020         else
00021                 return 2*n - 1 - (line/2);
00022 }
00023 
00024 int main()
00025 {
00026         n = 5;
00027 
00028         int store;
00029         std::vector<int> lines;
00030         std::vector<bool> done;
00031 
00032         lines.resize(2*n);
00033         done.resize(2*n);
00034 
00035         for (int t = 0; t <= n; t++) {
00036                 for (int i = 0; i < 2*n; i++) {
00037                         lines[i] = i;
00038                         done[i] = false;
00039                 }
00040 
00041                 for (int i = 0; i < 2*n; i++) {
00042                         if (done[i]) continue;
00043 
00044                         int j = i;
00045                         store = lines[j];
00046                         while (!done[j]) {
00047                                 done[j] = true;
00048                                 int newj = getLine(getIndex(j) + t);
00049                                 if (done[newj])
00050                                         lines[j] = store;
00051                                 else
00052                                         lines[j] = lines[newj];
00053                                 j = newj;
00054                         }
00055                 }
00056 
00057                 for (int i = 0; i < 2*n; i++) 
00058                         std::cout << lines[i] << " ";
00059                 std::cout << std::endl;
00060         }
00061         return 0;
00062 }

Generated on Fri Jul 27 22:27:19 2007 for pentagram by  doxygen 1.4.7