## Reinvent wheels, my quick sort implementation, just for fun

Not deeply optimized.
The depth of the recursion is restricted , because the recursion is only performed for the partition with less element. Even under the worst case, the stack depth will still be under control.
Tail recursion is eliminated.

Brief explanation:

 12345678910111213141516171819202122232425262728293031323334353637 initial state: p<<<                                      # p===                                      # |                                         p>>> p...                                      | |-----------------------------------------| ..........................................# state after choosing the pivot: p<<<                                      # p===                                      # |                                         p>>> |p...                                     | ||----------------------------------------| =.........................................# the middle state during partitioning: p<<<                                      # |        p===                             # |        |                          p>>>  # |        |         p...             |     # |--------|---------|----------------|-----# <<<<<<<<<==========.................>>>>>># the final state after partition: p<<<                                      # |               p===                      # |               |               p>>>      # |               |               p...      # |---------------|---------------|---------# <<<<<<<<<<<<<<<<================>>>>>>>>>># Then, recurse.

Pointer “p<<<" points to the begining of the "<<<" area in which each element is preceding to the pivot. Pointer "p===" points to the begining of the "===" area in which each element is equivalent to the pivot. Pointer "p>>>” points to the begining of the “>>>” area in which each element is succeeding to the pivot.
Pointer “p…” points to the begining of the “…” area in which each element is unprocessed.

The code:

 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 template class QuickSort { public:     static void sort(Elem pp[], size_t n) {         Elem *pe, *pu, *ps;         // pp:"p<<<", pe:"p===", ps:"p>>>", pu:"p..."         do {             // recursion exit, use other sort algorithm to process small array             // recommendation: use sorting network algorithm when array size less than 9             if(n < Cutoff) {                 ShortSort::sort(pp, n);                 return;             }             pe = pp;             pu = pp;             ps = pp+n;             // choosing pivot             swap(pe, pivot(pp, n));             pu++;             // partitioning             while(pu < ps) {                 while((*pe == *pu) && (pu < ps)) ++pu;                 while((*pe < *pu) && (pu < ps)) {                     --ps;                     swap(pu, ps);                 }                 while((*pu < *pe) && (pu < ps)) {                     swap(pe, pu);                     ++pe;                     ++pu;                 }             }             // recursion only for the partition with less elements             if((pe - pp) < (n - (ps - pp))) {                 sort(pp, pe - pp);                 n = n - (ps - pp);                 pp = ps;             } else {                 sort(ps, n - (ps - pp));                 n = pe - pp;             }             // tail recursion elimination         } while(true);     } private:     static Elem *pivot(Elem pp[], size_t n) {         if(n < 10) return pp + n/2;         else return pp + random(n);         // random(n) should return a uniformly distributed random number in [0, n)     } };

## Finding all paths from source to destination

 123456789101112131415161718 stack node_stack; set node_set; AllPathFromSourceToDestination(node s, node d) {     node_stack.push(s);     node_set.add(s); //mark each node in the path     // for each node v that adjacent with node s:     for_each(node v, adjacent(v,s)) {         if(v == d) {             Output(node_stack);         } else {             if(node_set.has(v)==false) {                 AllPathFromSourceToDestination(v, d);             }         }     }     node_set.del(s);     node_stack.pop(s); }

## Sorting network

The following is network-sorting algorithm for less than 33 elements.

What is Sorting Network? Wiki: sorting network

List of sorting networks:
From: sorting networks
Input the number n (maximum 32)
Algorithm choices: “Best”
Click [Take a look] button.

—————————
Zero-one principle

While it is easy to prove the validity of some sorting networks (like the insertion/bubble sorter), it is not always so easy. There are n! permutations of numbers in an n-wire network, and to test all of them would take a significant amount of time, especially when they are larger. However, because of the so-called zero-one principle, far fewer trials are in fact needed to test the validity of a sorting network.

The zero-one principle states that a sorting network is valid if it can sort all 2n sequences of 0s and 1s. This not only drastically cuts down on the number of tests needed to ascertain the validity of a network, it is of great use in creating many constructions of sorting networks as well. The principle has been proven by a special case of the Bouricius’s Theorem in 1954 by W. G. Bouricius.

 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 static const unsigned int network02[][2] = {     { 0, 1}, }; static const unsigned int network03[][2] = {     { 1, 2},     { 0, 2},     { 0, 1}, }; static const unsigned int network04[][2] = {     { 0, 1}, { 2, 3},     { 0, 2}, { 1, 3},     { 1, 2}, }; static const unsigned int network05[][2] = {     { 0, 1}, { 3, 4},     { 2, 4},     { 2, 3}, { 1, 4},     { 0, 3},     { 0, 2}, { 1, 3},     { 1, 2}, }; static const unsigned int network06[][2] = {     { 1, 2}, { 4, 5},     { 0, 2}, { 3, 5},     { 0, 1}, { 3, 4}, { 2, 5},     { 0, 3}, { 1, 4},     { 2, 4}, { 1, 3},     { 2, 3}, }; static const unsigned int network07[][2] = {     { 1, 2}, { 3, 4}, { 5, 6},     { 0, 2}, { 3, 5}, { 4, 6},     { 0, 1}, { 4, 5}, { 2, 6},     { 0, 4}, { 1, 5},     { 0, 3}, { 2, 5},     { 1, 3}, { 2, 4},     { 2, 3}, }; static const unsigned int network08[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 6, 7},     { 0, 2}, { 1, 3}, { 4, 6}, { 5, 7},     { 1, 2}, { 5, 6}, { 0, 4}, { 3, 7},     { 1, 5}, { 2, 6},     { 1, 4}, { 3, 6},     { 2, 4}, { 3, 5},     { 3, 4}, }; static const unsigned int network09[][2] = {     { 0, 1}, { 3, 4}, { 6, 7},     { 1, 2}, { 4, 5}, { 7, 8},     { 0, 1}, { 3, 4}, { 6, 7}, { 2, 5},     { 0, 3}, { 1, 4}, { 5, 8},     { 3, 6}, { 4, 7}, { 2, 5},     { 0, 3}, { 1, 4}, { 5, 7}, { 2, 6},     { 1, 3}, { 4, 6},     { 2, 4}, { 5, 6},     { 2, 3}, }; static const unsigned int network10[][2] = {     { 4, 9}, { 3, 8}, { 2, 7}, { 1, 6}, { 0, 5},     { 1, 4}, { 6, 9}, { 0, 3}, { 5, 8},     { 0, 2}, { 3, 6}, { 7, 9},     { 0, 1}, { 2, 4}, { 5, 7}, { 8, 9},     { 1, 2}, { 4, 6}, { 7, 8}, { 3, 5},     { 2, 5}, { 6, 8}, { 1, 3}, { 4, 7},     { 2, 3}, { 6, 7},     { 3, 4}, { 5, 6},     { 4, 5}, }; static const unsigned int network11[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 6, 7}, { 8, 9},     { 1, 3}, { 5, 7}, { 0, 2}, { 4, 6}, { 8,10},     { 1, 2}, { 5, 6}, { 9,10}, { 0, 4}, { 3, 7},     { 1, 5}, { 6,10}, { 4, 8},     { 5, 9}, { 2, 6}, { 0, 4}, { 3, 8},     { 1, 5}, { 6,10}, { 2, 3}, { 8, 9},     { 1, 4}, { 7,10}, { 3, 5}, { 6, 8},     { 2, 4}, { 7, 9}, { 5, 6},     { 3, 4}, { 7, 8}, }; static const unsigned int network12[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 6, 7}, { 8, 9}, {10,11},     { 1, 3}, { 5, 7}, { 9,11}, { 0, 2}, { 4, 6}, { 8,10},     { 1, 2}, { 5, 6}, { 9,10}, { 0, 4}, { 7,11},     { 1, 5}, { 6,10}, { 3, 7}, { 4, 8},     { 5, 9}, { 2, 6}, { 0, 4}, { 7,11}, { 3, 8},     { 1, 5}, { 6,10}, { 2, 3}, { 8, 9},     { 1, 4}, { 7,10}, { 3, 5}, { 6, 8},     { 2, 4}, { 7, 9}, { 5, 6},     { 3, 4}, { 7, 8}, }; static const unsigned int network13[][2] = {     { 1, 7}, { 9,11}, { 3, 4}, { 5, 8}, { 0,12}, { 2, 6},     { 0, 1}, { 2, 3}, { 4, 6}, { 8,11}, { 7,12}, { 5, 9},     { 0, 2}, { 3, 7}, {10,11}, { 1, 4}, { 6,12},     { 7, 8}, {11,12}, { 4, 9}, { 6,10},     { 3, 4}, { 5, 6}, { 8, 9}, {10,11}, { 1, 7},     { 2, 6}, { 9,11}, { 1, 3}, { 4, 7}, { 8,10}, { 0, 5},     { 2, 5}, { 6, 8}, { 9,10},     { 1, 2}, { 3, 5}, { 7, 8}, { 4, 6},     { 2, 3}, { 4, 5}, { 6, 7}, { 8, 9},     { 3, 4}, { 5, 6}, }; static const unsigned int network14[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 6, 7}, { 8, 9}, {10,11}, {12,13},     { 0, 2}, { 4, 6}, { 8,10}, { 1, 3}, { 5, 7}, { 9,11},     { 0, 4}, { 8,12}, { 1, 5}, { 9,13}, { 2, 6}, { 3, 7},     { 0, 8}, { 1, 9}, { 2,10}, { 3,11}, { 4,12}, { 5,13},     { 5,10}, { 6, 9}, { 3,12}, { 7,11}, { 1, 2}, { 4, 8},     { 1, 4}, { 7,13}, { 2, 8}, { 5, 6}, { 9,10},     { 2, 4}, {11,13}, { 3, 8}, { 7,12},     { 6, 8}, {10,12}, { 3, 5}, { 7, 9},     { 3, 4}, { 5, 6}, { 7, 8}, { 9,10}, {11,12},     { 6, 7}, { 8, 9}, }; static const unsigned int network15[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 6, 7}, { 8, 9}, {10,11}, {12,13},     { 0, 2}, { 4, 6}, { 8,10}, {12,14}, { 1, 3}, { 5, 7}, { 9,11},     { 0, 4}, { 8,12}, { 1, 5}, { 9,13}, { 2, 6}, {10,14}, { 3, 7},     { 0, 8}, { 1, 9}, { 2,10}, { 3,11}, { 4,12}, { 5,13}, { 6,14},     { 5,10}, { 6, 9}, { 3,12}, {13,14}, { 7,11}, { 1, 2}, { 4, 8},     { 1, 4}, { 7,13}, { 2, 8}, {11,14}, { 5, 6}, { 9,10},     { 2, 4}, {11,13}, { 3, 8}, { 7,12},     { 6, 8}, {10,12}, { 3, 5}, { 7, 9},     { 3, 4}, { 5, 6}, { 7, 8}, { 9,10}, {11,12},     { 6, 7}, { 8, 9}, }; static const unsigned int network16[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 6, 7}, { 8, 9}, {10,11}, {12,13}, {14,15},     { 0, 2}, { 4, 6}, { 8,10}, {12,14}, { 1, 3}, { 5, 7}, { 9,11}, {13,15},     { 0, 4}, { 8,12}, { 1, 5}, { 9,13}, { 2, 6}, {10,14}, { 3, 7}, {11,15},     { 0, 8}, { 1, 9}, { 2,10}, { 3,11}, { 4,12}, { 5,13}, { 6,14}, { 7,15},     { 5,10}, { 6, 9}, { 3,12}, {13,14}, { 7,11}, { 1, 2}, { 4, 8},     { 1, 4}, { 7,13}, { 2, 8}, {11,14}, { 5, 6}, { 9,10},     { 2, 4}, {11,13}, { 3, 8}, { 7,12},     { 6, 8}, {10,12}, { 3, 5}, { 7, 9},     { 3, 4}, { 5, 6}, { 7, 8}, { 9,10}, {11,12},     { 6, 7}, { 8, 9}, }; static const unsigned int network17[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 6, 7}, { 8, 9}, {10,11}, {12,13}, {15,16},     { 0, 2}, { 1, 3}, { 4, 6}, { 5, 7}, { 8,10}, { 9,11}, {14,16},     { 1, 2}, { 5, 6}, { 0, 4}, { 3, 7}, { 9,10}, {14,15}, {13,16},     { 1, 5}, { 2, 6}, {12,15}, {11,16},     { 1, 4}, { 3, 6}, {12,14}, {13,15}, { 7,16},     { 2, 4}, { 3, 5}, {13,14}, {10,15},     { 3, 4}, { 8,13}, { 9,14}, {11,15},     { 8,12}, { 9,13}, {11,14}, { 6,15},     { 9,12}, {10,13}, { 5,14}, { 7,15},     {10,12}, {11,13}, { 0, 9}, { 7,14},     {11,12}, { 0, 8}, { 1,10}, { 4,13},     { 1, 9}, { 2,11}, { 3,12}, { 5,13},     { 1, 8}, { 3,11}, { 2, 9}, { 6,13},     { 2, 8}, { 3,10}, { 7,13}, { 6,11},     { 3, 9}, { 5,10}, { 7,12},     { 3, 8}, { 4, 9}, { 7,11},     { 4, 8}, { 5, 9}, { 7,10},     { 5, 8}, { 6, 9},     { 6, 8}, { 7, 9},     { 7, 8}, }; static const unsigned int network18[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 7, 8}, { 9,10}, {11,12}, {13,14}, {16,17},     { 0, 2}, { 1, 3}, { 6, 8}, { 9,11}, {10,12}, {15,17},     { 1, 2}, { 6, 7}, { 5, 8}, {10,11}, {15,16}, {14,17},     { 4, 7}, { 3, 8}, {13,16}, {12,17},     { 4, 6}, { 5, 7}, {13,15}, {14,16}, { 8,17},     { 5, 6}, { 2, 7}, {14,15}, {11,16},     { 0, 5}, { 1, 6}, { 3, 7}, { 9,14}, {10,15}, {12,16},     { 0, 4}, { 1, 5}, { 3, 6}, { 9,13}, {10,14}, {12,15}, { 7,16},     { 1, 4}, { 2, 5}, {10,13}, {11,14}, { 0, 9}, { 6,15}, { 8,16},     { 2, 4}, { 3, 5}, {11,13}, {12,14}, { 1,10}, { 7,15},     { 3, 4}, {12,13}, { 1, 9}, { 2,11}, { 5,14}, { 8,15},     { 3,12}, { 2, 9}, { 4,13}, { 7,14},     { 3,11}, { 5,13}, { 8,14},     { 3,10}, { 6,13},     { 3, 9}, { 7,13}, { 5,10}, { 6,11},     { 8,13}, { 4, 9}, { 7,12},     { 5, 9}, { 8,12}, { 7,11},     { 8,11}, { 6, 9}, { 7,10},     { 8,10}, { 7, 9},     { 8, 9}, }; static const unsigned int network19[][2] = {     { 0, 1}, { 2, 3}, { 4, 5}, { 7, 8}, { 9,10}, {12,13}, {14,15}, {17,18},     { 0, 2}, { 1, 3}, { 6, 8}, {11,13}, {16,18},     { 1, 2}, { 6, 7}, { 5, 8}, {11,12}, {10,13}, {16,17}, {15,18},     { 4, 7}, { 3, 8}, { 9,12}, {14,17}, {13,18},     { 4, 6}, { 5, 7}, { 9,11}, {10,12}, {14,16}, {15,17}, { 8,18},     { 5, 6}, { 2, 7}, {10,11}, {15,16}, { 9,14}, {12,17},     { 0, 5}, { 1, 6}, { 3, 7}, {10,15}, {11,16}, {13,17},     { 0, 4}, { 1, 5}, { 3, 6}, {10,14}, {12,16}, { 7,17},     { 1, 4}, { 2, 5}, {13,16}, {11,14}, {12,15}, { 0,10}, { 8,17},     { 2, 4}, { 3, 5}, {13,15}, {12,14}, { 0, 9}, { 1,11}, { 6,16},     { 3, 4}, {13,14}, { 1,10}, { 2,12}, { 5,15}, { 7,16},     { 1, 9}, { 3,13}, { 2,10}, { 4,14}, { 8,16}, { 7,15},     { 3,12}, { 2, 9}, { 5,14}, { 8,15},     { 3,11}, { 6,14},     { 3,10}, { 7,14}, { 6,11},     { 3, 9}, { 8,14}, { 5,10}, { 7,12},     { 4, 9}, { 8,13}, { 7,11},     { 5, 9}, { 8,12}, { 7,10},     { 8,11}, { 6, 9},     { 8,10}, { 7, 9},     { 8, 9}, }; static const unsigned int network20[][2] = {     { 0, 1}, { 3, 4}, { 5, 6}, { 8, 9}, {10,11}, {13,14}, {15,16}, {18,19},     { 2, 4}, { 7, 9}, {12,14}, {17,19},     { 2, 3}, { 1, 4}, { 7, 8}, { 6, 9}, {12,13}, {11,14}, {17,18}, {16,19},     { 0, 3}, { 5, 8}, { 4, 9}, {10,13}, {15,18}, {14,19},     { 0, 2}, { 1, 3}, { 5, 7}, { 6, 8}, {10,12}, {11,13}, {15,17}, {16,18}, { 9,19},     { 1, 2}, { 6, 7}, { 0, 5}, { 3, 8}, {11,12}, {16,17}, {10,15}, {13,18},     { 1, 6}, { 2, 7}, { 4, 8}, {11,16}, {12,17}, {14,18}, { 0,10},     { 1, 5}, { 3, 7}, {11,15}, {13,17}, { 8,18},     { 4, 7}, { 2, 5}, { 3, 6}, {14,17}, {12,15}, {13,16}, { 1,11}, { 9,18},     { 4, 6}, { 3, 5}, {14,16}, {13,15}, { 1,10}, { 2,12}, { 7,17},     { 4, 5}, {14,15}, { 3,13}, { 2,10}, { 6,16}, { 8,17},     { 4,14}, { 3,12}, { 5,15}, { 9,17}, { 8,16},     { 4,13}, { 3,11}, { 6,15}, { 9,16},     { 4,12}, { 3,10}, { 7,15},     { 4,11}, { 8,15}, { 7,12},     { 4,10}, { 9,15}, { 6,11}, { 8,13},     { 5,10}, { 9,14}, { 8,12},     { 6,10}, { 9,13}, { 8,11},     { 9,12}, { 7,10},     { 9,11}, { 8,10},     { 9,10}, }; static const unsigned int network21[][2] = {     { 0, 1}, { 3, 4}, { 5, 6}, { 8, 9}, {10,11}, {13,14}, {16,17}, {19,20},     { 2, 4}, { 7, 9}, {12,14}, {15,17}, {18,20},     { 2, 3}, { 1, 4}, { 7, 8}, { 6, 9}, {12,13}, {11,14}, {15,16}, {18,19}, {17,20},     { 0, 3}, { 5, 8}, { 4, 9}, {10,13}, {15,18}, {16,19}, {14,20},     { 0, 2}, { 1, 3}, { 5, 7}, { 6, 8}, {10,12}, {11,13}, {17,19}, {16,18}, { 9,20},     { 1, 2}, { 6, 7}, { 0, 5}, { 3, 8}, {11,12}, {17,18}, {10,16}, {13,19},     { 1, 6}, { 2, 7}, { 4, 8}, {10,15}, {11,17}, {12,18}, {14,19},     { 1, 5}, { 3, 7}, {11,16}, {13,18}, { 8,19},     { 4, 7}, { 2, 5}, { 3, 6}, {11,15}, {14,18}, {13,16}, { 9,19},     { 4, 6}, { 3, 5}, {12,15}, {14,17}, { 0,11}, { 7,18},     { 4, 5}, {14,16}, {13,15}, { 0,10}, { 1,12}, { 6,17}, { 8,18},     {14,15}, { 1,11}, { 2,13}, { 5,16}, { 9,18}, { 8,17},     { 1,10}, { 3,14}, { 4,15}, { 6,16}, { 9,17},     { 4,14}, { 3,13}, { 2,10}, { 7,16},     { 4,13}, { 3,11}, { 8,16},     { 4,12}, { 3,10}, { 9,16}, { 7,13}, { 8,14},     { 4,11}, { 6,12}, { 9,15}, { 8,13},     { 4,10}, { 5,11}, { 9,14},     { 5,10}, { 6,11}, { 9,13},     { 6,10}, { 8,11}, { 9,12},     { 7,10}, { 9,11},     { 8,10},     { 9,10}, }; static const unsigned int network22[][2] = {     { 0, 1}, { 3, 4}, { 6, 7}, { 9,10}, {11,12}, {14,15}, {17,18}, {20,21},     { 2, 4}, { 5, 7}, { 8,10}, {13,15}, {16,18}, {19,21},     { 2, 3}, { 1, 4}, { 5, 6}, { 8, 9}, { 7,10}, {13,14}, {12,15}, {16,17}, {19,20}, {18,21},     { 0, 3}, { 5, 8}, { 6, 9}, { 4,10}, {11,14}, {16,19}, {17,20}, {15,21},     { 0, 2}, { 1, 3}, { 7, 9}, { 6, 8}, {11,13}, {12,14}, {18,20}, {17,19}, {10,21},     { 1, 2}, { 7, 8}, { 0, 6}, { 3, 9}, {12,13}, {18,19}, {11,17}, {14,20},     { 0, 5}, { 1, 7}, { 2, 8}, { 4, 9}, {11,16}, {12,18}, {13,19}, {15,20},     { 1, 6}, { 3, 8}, {12,17}, {14,19}, { 0,11}, { 9,20},     { 1, 5}, { 4, 8}, { 3, 6}, {12,16}, {15,19}, {14,17}, {10,20},     { 2, 5}, { 4, 7}, {13,16}, {15,18}, { 1,12}, { 8,19},     { 4, 6}, { 3, 5}, {15,17}, {14,16}, { 1,11}, { 2,13}, { 7,18}, { 9,19},     { 4, 5}, {15,16}, { 3,14}, { 2,11}, { 6,17}, {10,19},     { 4,15}, { 3,13}, { 5,16}, { 7,17}, {10,18},     { 4,14}, { 3,12}, { 6,16}, { 9,17},     { 4,13}, { 3,11}, { 7,16}, {10,17},     { 4,12}, { 8,16}, { 7,13},     { 4,11}, { 9,16}, { 6,12}, { 8,14},     {10,16}, { 5,11}, { 7,12}, { 9,15},     { 6,11}, {10,15}, { 9,14},     { 7,11}, {10,14}, { 9,12},     { 8,11}, {10,13},     {10,12}, { 9,11},     {10,11}, }; static const unsigned int network23[][2] = {     { 0, 1}, { 3, 4}, { 6, 7}, { 9,10}, {12,13}, {15,16}, {18,19}, {21,22},     { 2, 4}, { 5, 7}, { 8,10}, {11,13}, {14,16}, {17,19}, {20,22},     { 2, 3}, { 1, 4}, { 5, 6}, { 8, 9}, { 7,10}, {11,12}, {14,15}, {13,16}, {17,18}, {20,21}, {19,22},     { 0, 3}, { 5, 8}, { 6, 9}, { 4,10}, {11,14}, {12,15}, {17,20}, {18,21}, {16,22},     { 0, 2}, { 1, 3}, { 7, 9}, { 6, 8}, {13,15}, {12,14}, {19,21}, {18,20}, {11,17}, {10,22},     { 1, 2}, { 7, 8}, { 0, 6}, { 3, 9}, {13,14}, {19,20}, {12,18}, {15,21},     { 0, 5}, { 1, 7}, { 2, 8}, { 4, 9}, {13,19}, {12,17}, {14,20}, {16,21},     { 1, 6}, { 3, 8}, {13,18}, {15,20}, { 0,12}, { 9,21},     { 1, 5}, { 4, 8}, { 3, 6}, {13,17}, {16,20}, {15,18}, { 0,11}, {10,21},     { 2, 5}, { 4, 7}, {14,17}, {16,19}, { 1,13}, { 8,20},     { 4, 6}, { 3, 5}, {16,18}, {15,17}, { 1,12}, { 2,14}, { 7,19}, { 9,20},     { 4, 5}, {16,17}, { 1,11}, { 3,15}, { 6,18}, {10,20},     { 4,16}, { 3,14}, { 2,11}, { 5,17}, { 7,18}, {10,19},     { 4,15}, { 3,12}, { 6,17}, { 9,18},     { 4,14}, { 3,11}, { 7,17}, {10,18},     { 4,13}, { 8,17},     { 4,12}, { 9,17}, { 7,13}, { 8,14},     { 4,11}, {10,17}, { 6,12}, { 9,15},     { 5,11}, { 7,12}, {10,16}, { 9,14},     { 6,11}, {10,15}, { 9,12},     { 7,11}, {10,14},     { 8,11}, {10,13},     {10,12}, { 9,11},     {10,11}, }; static const unsigned int network24[][2] = {     { 1, 2}, { 4, 5}, { 7, 8}, {10,11}, {13,14}, {16,17}, {19,20}, {22,23},     { 0, 2}, { 3, 5}, { 6, 8}, { 9,11}, {12,14}, {15,17}, {18,20}, {21,23},     { 0, 1}, { 3, 4}, { 2, 5}, { 6, 7}, { 9,10}, { 8,11}, {12,13}, {15,16}, {14,17}, {18,19}, {21,22}, {20,23},     { 0, 3}, { 1, 4}, { 6, 9}, { 7,10}, { 5,11}, {12,15}, {13,16}, {18,21}, {19,22}, {17,23},     { 2, 4}, { 1, 3}, { 8,10}, { 7, 9}, { 0, 6}, {14,16}, {13,15}, {20,22}, {19,21}, {12,18}, {11,23},     { 2, 3}, { 8, 9}, { 1, 7}, { 4,10}, {14,15}, {20,21}, {13,19}, {16,22}, { 0,12},     { 2, 8}, { 1, 6}, { 3, 9}, { 5,10}, {14,20}, {13,18}, {15,21}, {17,22},     { 2, 7}, { 4, 9}, {14,19}, {16,21}, { 1,13}, {10,22},     { 2, 6}, { 5, 9}, { 4, 7}, {14,18}, {17,21}, {16,19}, { 1,12}, {11,22},     { 3, 6}, { 5, 8}, {15,18}, {17,20}, { 2,14}, { 9,21},     { 5, 7}, { 4, 6}, {17,19}, {16,18}, { 2,13}, { 3,15}, { 8,20}, {10,21},     { 5, 6}, {17,18}, { 2,12}, { 4,16}, { 7,19}, {11,21},     { 5,17}, { 4,15}, { 3,12}, { 6,18}, { 8,19}, {11,20},     { 5,16}, { 4,13}, { 7,18}, {10,19},     { 5,15}, { 4,12}, { 8,18}, {11,19},     { 5,14}, { 9,18},     { 5,13}, {10,18}, { 8,14}, { 9,15},     { 5,12}, {11,18}, { 7,13}, {10,16},     { 6,12}, { 8,13}, {11,17}, {10,15},     { 7,12}, {11,16}, {10,13},     { 8,12}, {11,15},     { 9,12}, {11,14},     {11,13}, {10,12},     {11,12}, }; static const unsigned int network25[][2] = {     { 1, 2}, { 4, 5}, { 7, 8}, {10,11}, {13,14}, {16,17}, {19,20}, {21,22}, {23,24},     { 0, 2}, { 3, 5}, { 6, 8}, { 9,11}, {12,14}, {15,17}, {18,20}, {21,23}, {22,24},     { 0, 1}, { 3, 4}, { 2, 5}, { 6, 7}, { 9,10}, { 8,11}, {12,13}, {15,16}, {14,17}, {18,19}, {22,23}, {20,24},     { 0, 3}, { 1, 4}, { 6, 9}, { 7,10}, { 5,11}, {12,15}, {13,16}, {18,22}, {19,23}, {17,24},     { 2, 4}, { 1, 3}, { 8,10}, { 7, 9}, { 0, 6}, {14,16}, {13,15}, {18,21}, {20,23}, {11,24},     { 2, 3}, { 8, 9}, { 1, 7}, { 4,10}, {14,15}, {19,21}, {20,22}, {16,23},     { 2, 8}, { 1, 6}, { 3, 9}, { 5,10}, {20,21}, {12,19}, {15,22}, {17,23},     { 2, 7}, { 4, 9}, {12,18}, {13,20}, {14,21}, {16,22}, {10,23},     { 2, 6}, { 5, 9}, { 4, 7}, {14,20}, {13,18}, {17,22}, {11,23},     { 3, 6}, { 5, 8}, {14,19}, {16,20}, {17,21}, { 0,13}, { 9,22},     { 5, 7}, { 4, 6}, {14,18}, {15,19}, {17,20}, { 0,12}, { 8,21}, {10,22},     { 5, 6}, {15,18}, {17,19}, { 1,14}, { 7,20}, {11,22},     {16,18}, { 2,15}, { 1,12}, { 6,19}, { 8,20}, {11,21},     {17,18}, { 2,14}, { 3,16}, { 7,19}, {10,20},     { 2,13}, { 4,17}, { 5,18}, { 8,19}, {11,20},     { 2,12}, { 5,17}, { 4,16}, { 3,13}, { 9,19},     { 5,16}, { 3,12}, { 4,14}, {10,19},     { 5,15}, { 4,12}, {11,19}, { 9,16}, {10,17},     { 5,14}, { 8,15}, {11,18}, {10,16},     { 5,13}, { 7,14}, {11,17},     { 5,12}, { 6,13}, { 8,14}, {11,16},     { 6,12}, { 8,13}, {10,14}, {11,15},     { 7,12}, { 9,13}, {11,14},     { 8,12}, {11,13},     { 9,12},     {10,12},     {11,12}, }; static const unsigned int network26[][2] = {     { 1, 2}, { 4, 5}, { 7, 8}, { 9,10}, {11,12}, {14,15}, {17,18}, {20,21}, {22,23}, {24,25},     { 0, 2}, { 3, 5}, { 6, 8}, { 9,11}, {10,12}, {13,15}, {16,18}, {19,21}, {22,24}, {23,25},     { 0, 1}, { 3, 4}, { 2, 5}, { 6, 7}, {10,11}, { 8,12}, {13,14}, {16,17}, {15,18}, {19,20}, {23,24}, {21,25},     { 0, 3}, { 1, 4}, { 6,10}, { 7,11}, { 5,12}, {13,16}, {14,17}, {19,23}, {20,24}, {18,25},     { 2, 4}, { 1, 3}, { 6, 9}, { 8,11}, {15,17}, {14,16}, {19,22}, {21,24}, {12,25},     { 2, 3}, { 7, 9}, { 8,10}, { 4,11}, {15,16}, {20,22}, {21,23}, {17,24},     { 8, 9}, { 0, 7}, { 3,10}, { 5,11}, {21,22}, {13,20}, {16,23}, {18,24},     { 0, 6}, { 1, 8}, { 2, 9}, { 4,10}, {13,19}, {14,21}, {15,22}, {17,23}, {11,24},     { 2, 8}, { 1, 6}, { 5,10}, {15,21}, {14,19}, {18,23}, { 0,13}, {12,24},     { 2, 7}, { 4, 8}, { 5, 9}, {15,20}, {17,21}, {18,22}, { 1,14}, {10,23},     { 2, 6}, { 3, 7}, { 5, 8}, {15,19}, {16,20}, {18,21}, { 1,13}, { 9,22}, {12,23},     { 3, 6}, { 5, 7}, {16,19}, {18,20}, { 2,15}, { 8,21}, {10,22},     { 4, 6}, {17,19}, { 2,14}, { 3,16}, { 7,20}, {11,22},     { 5, 6}, {18,19}, { 2,13}, { 4,17}, { 8,20}, {12,22}, {11,21},     { 5,18}, { 4,16}, { 3,13}, { 6,19}, {10,20}, {12,21},     { 5,17}, { 4,14}, { 7,19}, {12,20},     { 5,16}, { 4,13}, { 8,19},     { 5,15}, { 9,19},     { 5,14}, {10,19}, { 8,15}, { 9,16},     { 5,13}, {11,19}, { 7,14}, {10,17},     {12,19}, { 6,13}, { 8,14}, {10,16}, {11,18},     { 7,13}, {12,18}, {11,16}, {10,14},     { 8,13}, {12,17}, {11,15},     {12,16}, { 9,13},     {10,13}, {12,15},     {11,13}, {12,14},     {12,13}, }; static const unsigned int network27[][2] = {     { 1, 2}, { 4, 5}, { 7, 8}, { 9,10}, {11,12}, {14,15}, {16,17}, {18,19}, {21,22}, {23,24}, {25,26},     { 0, 2}, { 3, 5}, { 6, 8}, { 9,11}, {10,12}, {13,15}, {16,18}, {17,19}, {20,22}, {23,25}, {24,26},     { 0, 1}, { 3, 4}, { 2, 5}, { 6, 7}, {10,11}, { 8,12}, {13,14}, {17,18}, {15,19}, {20,21}, {24,25}, {22,26},     { 0, 3}, { 1, 4}, { 6,10}, { 7,11}, { 5,12}, {13,17}, {14,18}, {20,24}, {21,25}, {19,26},     { 2, 4}, { 1, 3}, { 6, 9}, { 8,11}, {13,16}, {15,18}, {20,23}, {22,25}, {12,26},     { 2, 3}, { 7, 9}, { 8,10}, { 4,11}, {14,16}, {15,17}, {21,23}, {22,24}, {13,20}, {18,25},     { 8, 9}, { 0, 7}, { 3,10}, { 5,11}, {15,16}, {22,23}, {14,21}, {17,24}, {19,25},     { 0, 6}, { 1, 8}, { 2, 9}, { 4,10}, {15,22}, {14,20}, {16,23}, {19,24}, {11,25},     { 2, 8}, { 1, 6}, { 5,10}, {15,21}, {17,23}, { 0,14}, {12,25},     { 2, 7}, { 4, 8}, { 5, 9}, {15,20}, {18,23}, {17,21}, { 0,13}, {10,24},     { 2, 6}, { 3, 7}, { 5, 8}, {19,23}, {16,20}, {18,22}, { 1,15}, {12,24},     { 3, 6}, { 5, 7}, {17,20}, {19,22}, { 2,16}, { 1,13}, { 9,23},     { 4, 6}, {18,20}, {19,21}, { 2,15}, { 3,17}, { 8,22}, {10,23},     { 5, 6}, {19,20}, { 2,14}, { 4,18}, { 7,21}, {11,23},     { 2,13}, { 5,19}, { 4,17}, { 3,14}, { 6,20}, { 8,21}, {12,23}, {11,22},     { 5,18}, { 3,13}, { 4,15}, { 7,20}, {10,21}, {12,22},     { 5,17}, { 4,13}, { 8,20}, {12,21},     { 5,16}, { 9,20},     { 5,15}, {10,20}, { 9,16},     { 5,14}, {11,20}, { 8,15}, {10,17},     { 5,13}, {12,20}, { 7,14}, {10,16}, {11,18},     { 6,13}, { 8,14}, {12,19}, {11,16},     { 7,13}, {12,18}, {10,14}, {11,15},     { 8,13}, {12,17},     {12,16}, { 9,13},     {10,13}, {12,15},     {11,13}, {12,14},     {12,13}, }; static const unsigned int network28[][2] = {     { 1, 2}, { 3, 4}, { 5, 6}, { 8, 9}, {10,11}, {12,13}, {15,16}, {17,18}, {19,20}, {22,23}, {24,25}, {26,27},     { 0, 2}, { 3, 5}, { 4, 6}, { 7, 9}, {10,12}, {11,13}, {14,16}, {17,19}, {18,20}, {21,23}, {24,26}, {25,27},     { 0, 1}, { 4, 5}, { 2, 6}, { 7, 8}, {11,12}, { 9,13}, {14,15}, {18,19}, {16,20}, {21,22}, {25,26}, {23,27},     { 0, 4}, { 1, 5}, { 7,11}, { 8,12}, { 6,13}, {14,18}, {15,19}, {21,25}, {22,26}, {20,27},     { 0, 3}, { 2, 5}, { 7,10}, { 9,12}, {14,17}, {16,19}, {21,24}, {23,26}, {13,27},     { 1, 3}, { 2, 4}, { 8,10}, { 9,11}, { 0, 7}, { 5,12}, {15,17}, {16,18}, {22,24}, {23,25}, {14,21}, {19,26},     { 2, 3}, { 9,10}, { 1, 8}, { 4,11}, { 6,12}, {16,17}, {23,24}, {15,22}, {18,25}, {20,26}, { 0,14},     { 2, 9}, { 1, 7}, { 3,10}, { 6,11}, {16,23}, {15,21}, {17,24}, {20,25}, {12,26},     { 2, 8}, { 4,10}, {16,22}, {18,24}, { 1,15}, {11,25}, {13,26},     { 2, 7}, { 5,10}, { 4, 8}, {16,21}, {19,24}, {18,22}, { 1,14}, {13,25},     { 6,10}, { 3, 7}, { 5, 9}, {20,24}, {17,21}, {19,23}, { 2,16},     { 4, 7}, { 6, 9}, {18,21}, {20,23}, { 2,15}, { 3,17}, {10,24},     { 5, 7}, { 6, 8}, {19,21}, {20,22}, { 2,14}, { 4,18}, { 9,23}, {11,24},     { 6, 7}, {20,21}, { 4,17}, { 5,19}, { 3,14}, { 8,22}, {12,24},     { 6,20}, { 5,17}, { 4,15}, { 7,21}, { 9,22}, {13,24}, {12,23},     { 6,19}, { 4,14}, { 5,16}, { 8,21}, {11,22}, {13,23},     { 6,18}, { 5,14}, { 9,21}, {13,22},     { 6,17}, {10,21},     { 6,16}, {11,21}, {10,17},     { 6,15}, {12,21}, { 9,16}, {11,18},     { 6,14}, {13,21}, { 8,15}, {11,17}, {12,19},     { 7,14}, { 9,15}, {13,20}, {12,17},     { 8,14}, {13,19}, {11,15}, {12,16},     { 9,14}, {13,18},     {13,17}, {10,14},     {11,14}, {13,16},     {12,14}, {13,15},     {13,14}, }; static const unsigned int network29[][2] = {     { 1, 2}, { 3, 4}, { 5, 6}, { 8, 9}, {10,11}, {12,13}, {15,16}, {17,18}, {19,20}, {21,22}, {23,24}, {25,26}, {27,28},     { 0, 2}, { 3, 5}, { 4, 6}, { 7, 9}, {10,12}, {11,13}, {14,16}, {17,19}, {18,20}, {21,23}, {22,24}, {25,27}, {26,28},     { 0, 1}, { 4, 5}, { 2, 6}, { 7, 8}, {11,12}, { 9,13}, {14,15}, {18,19}, {16,20}, {22,23}, {26,27}, {21,25}, {24,28},     { 0, 4}, { 1, 5}, { 7,11}, { 8,12}, { 6,13}, {14,18}, {15,19}, {22,26}, {23,27}, {20,28},     { 0, 3}, { 2, 5}, { 7,10}, { 9,12}, {14,17}, {16,19}, {22,25}, {24,27}, {13,28},     { 1, 3}, { 2, 4}, { 8,10}, { 9,11}, { 0, 7}, { 5,12}, {15,17}, {16,18}, {23,25}, {24,26}, {14,22}, {19,27},     { 2, 3}, { 9,10}, { 1, 8}, { 4,11}, { 6,12}, {16,17}, {24,25}, {14,21}, {15,23}, {18,26}, {20,27},     { 2, 9}, { 1, 7}, { 3,10}, { 6,11}, {16,24}, {15,21}, {17,25}, {20,26}, {12,27},     { 2, 8}, { 4,10}, {16,23}, {18,25}, { 0,15}, {11,26}, {13,27},     { 2, 7}, { 5,10}, { 4, 8}, {16,22}, {19,25}, { 0,14}, {13,26},     { 6,10}, { 3, 7}, { 5, 9}, {16,21}, {20,25}, {18,22}, {19,23},     { 4, 7}, { 6, 9}, {17,21}, {20,24}, { 1,16}, {10,25},     { 5, 7}, { 6, 8}, {18,21}, {20,23}, { 2,17}, { 1,14}, { 9,24}, {11,25},     { 6, 7}, {19,21}, {20,22}, { 2,16}, { 3,18}, { 8,23}, {12,25},     {20,21}, { 2,15}, { 4,19}, { 7,22}, { 9,23}, {13,25}, {12,24},     { 2,14}, { 4,18}, { 5,20}, { 6,21}, { 8,22}, {11,23}, {13,24},     { 6,20}, { 5,18}, { 3,14}, { 4,15}, { 9,22}, {13,23},     { 6,19}, { 4,14}, { 5,16}, {10,22},     { 6,18}, { 5,14}, {11,22},     { 6,17}, {12,22}, {10,18}, {11,19},     { 6,16}, {13,22}, { 9,17}, {11,18}, {12,20},     { 6,15}, { 8,16}, {13,21}, {12,18},     { 6,14}, { 7,15}, { 9,16}, {13,20},     { 7,14}, { 9,15}, {13,19}, {12,16},     { 8,14}, {13,18}, {11,15},     { 9,14}, {13,17},     {10,14}, {13,16},     {11,14}, {13,15},     {12,14},     {13,14}, }; static const unsigned int network30[][2] = {     { 1, 2}, { 3, 4}, { 5, 6}, { 7, 8}, { 9,10}, {11,12}, {13,14}, {16,17}, {18,19}, {20,21}, {22,23}, {24,25}, {26,27}, {28,29},     { 0, 2}, { 3, 5}, { 4, 6}, { 7, 9}, { 8,10}, {11,13}, {12,14}, {15,17}, {18,20}, {19,21}, {22,24}, {23,25}, {26,28}, {27,29},     { 0, 1}, { 4, 5}, { 2, 6}, { 8, 9}, {12,13}, { 7,11}, {10,14}, {15,16}, {19,20}, {17,21}, {23,24}, {27,28}, {22,26}, {25,29},     { 0, 4}, { 1, 5}, { 8,12}, { 9,13}, { 6,14}, {15,19}, {16,20}, {23,27}, {24,28}, {21,29},     { 0, 3}, { 2, 5}, { 8,11}, {10,13}, {15,18}, {17,20}, {23,26}, {25,28}, {14,29},     { 1, 3}, { 2, 4}, { 9,11}, {10,12}, { 0, 8}, { 5,13}, {16,18}, {17,19}, {24,26}, {25,27}, {15,23}, {20,28},     { 2, 3}, {10,11}, { 0, 7}, { 1, 9}, { 4,12}, { 6,13}, {17,18}, {25,26}, {15,22}, {16,24}, {19,27}, {21,28},     { 2,10}, { 1, 7}, { 3,11}, { 6,12}, {17,25}, {16,22}, {18,26}, {21,27}, { 0,15}, {13,28},     { 2, 9}, { 4,11}, {17,24}, {19,26}, { 1,16}, {12,27}, {14,28},     { 2, 8}, { 5,11}, {17,23}, {20,26}, { 1,15}, {14,27},     { 2, 7}, { 6,11}, { 4, 8}, { 5, 9}, {17,22}, {21,26}, {19,23}, {20,24},     { 3, 7}, { 6,10}, {18,22}, {21,25}, { 2,17}, {11,26},     { 4, 7}, { 6, 9}, {19,22}, {21,24}, { 2,16}, { 3,18}, {10,25}, {12,26},     { 5, 7}, { 6, 8}, {20,22}, {21,23}, { 2,15}, { 4,19}, { 9,24}, {13,26},     { 6, 7}, {21,22}, { 4,18}, { 5,20}, { 3,15}, { 8,23}, {10,24}, {14,26},     { 6,21}, { 5,18}, { 4,16}, { 7,22}, {10,23}, {13,24}, {14,25},     { 6,20}, { 4,15}, { 5,17}, { 8,22}, {12,23}, {14,24},     { 6,19}, { 5,15}, { 9,22}, {14,23},     { 6,18}, {10,22},     { 6,17}, {11,22}, {10,18},     { 6,16}, {12,22}, { 9,17}, {11,19},     { 6,15}, {13,22}, { 8,16}, {10,17}, {12,20},     {14,22}, { 7,15}, {10,16}, {12,19}, {13,21},     { 8,15}, {14,21}, {13,19}, {12,16},     { 9,15}, {14,20}, {13,17},     {10,15}, {14,19},     {11,15}, {14,18},     {12,15}, {14,17},     {13,15}, {14,16},     {14,15}, }; static const unsigned int network31[][2] = {     { 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},     { 0, 2}, { 3, 5}, { 4, 6}, { 7, 9}, { 8,10}, {11,13}, {12,14}, {15,17}, {16,18}, {19,21}, {20,22}, {23,25}, {24,26}, {27,29}, {28,30},     { 0, 1}, { 4, 5}, { 2, 6}, { 8, 9}, {12,13}, { 7,11}, {10,14}, {16,17}, {20,21}, {15,19}, {18,22}, {24,25}, {28,29}, {23,27}, {26,30},     { 0, 4}, { 1, 5}, { 8,12}, { 9,13}, { 6,14}, {16,20}, {17,21}, {24,28}, {25,29}, {15,23}, {22,30},     { 0, 3}, { 2, 5}, { 8,11}, {10,13}, {16,19}, {18,21}, {24,27}, {26,29}, {14,30},     { 1, 3}, { 2, 4}, { 9,11}, {10,12}, { 0, 8}, { 5,13}, {17,19}, {18,20}, {25,27}, {26,28}, {16,24}, {21,29},     { 2, 3}, {10,11}, { 0, 7}, { 1, 9}, { 4,12}, { 6,13}, {18,19}, {26,27}, {16,23}, {17,25}, {20,28}, {22,29},     { 2,10}, { 1, 7}, { 3,11}, { 6,12}, {18,26}, {17,23}, {19,27}, {22,28}, { 0,16}, {13,29},     { 2, 9}, { 4,11}, {18,25}, {20,27}, { 0,15}, { 1,17}, {12,28}, {14,29},     { 2, 8}, { 5,11}, {18,24}, {21,27}, { 1,15}, {14,28},     { 2, 7}, { 6,11}, { 4, 8}, { 5, 9}, {18,23}, {22,27}, {20,24}, {21,25},     { 3, 7}, { 6,10}, {19,23}, {22,26}, { 2,18}, {11,27},     { 4, 7}, { 6, 9}, {20,23}, {22,25}, { 2,17}, { 3,19}, {10,26}, {12,27},     { 5, 7}, { 6, 8}, {21,23}, {22,24}, { 2,16}, { 4,20}, { 9,25}, {13,27},     { 6, 7}, {22,23}, { 2,15}, { 4,19}, { 5,21}, { 8,24}, {10,25}, {14,27},     { 6,22}, { 5,19}, { 3,15}, { 4,16}, { 7,23}, {10,24}, {13,25}, {14,26},     { 6,21}, { 4,15}, { 5,17}, { 8,23}, {12,24}, {14,25},     { 6,20}, { 5,15}, { 9,23}, {14,24},     { 6,19}, {10,23},     { 6,18}, {11,23},     { 6,17}, {12,23}, {10,18}, {11,19},     { 6,16}, {13,23}, { 9,17}, {12,20},     { 6,15}, {14,23}, { 8,16}, {10,17}, {12,19}, {13,21},     { 7,15}, {10,16}, {14,22}, {13,19},     { 8,15}, {14,21}, {12,16}, {13,17},     { 9,15}, {14,20},     {10,15}, {14,19},     {11,15}, {14,18},     {12,15}, {14,17},     {13,15}, {14,16},     {14,15}, }; static const unsigned int network32[][2] = {     { 0, 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},     { 0, 2}, { 1, 3}, { 4, 6}, { 5, 7}, { 8,10}, { 9,11}, {12,14}, {13,15}, {16,18}, {17,19}, {20,22}, {21,23}, {24,26}, {25,27}, {28,30}, {29,31},     { 1, 2}, { 5, 6}, { 0, 4}, { 3, 7}, { 9,10}, {13,14}, { 8,12}, {11,15}, {17,18}, {21,22}, {16,20}, {19,23}, {25,26}, {29,30}, {24,28}, {27,31},     { 1, 5}, { 2, 6}, { 9,13}, {10,14}, { 0, 8}, { 7,15}, {17,21}, {18,22}, {25,29}, {26,30}, {16,24}, {23,31},     { 1, 4}, { 3, 6}, { 9,12}, {11,14}, {17,20}, {19,22}, {25,28}, {27,30}, { 0,16}, {15,31},     { 2, 4}, { 3, 5}, {10,12}, {11,13}, { 1, 9}, { 6,14}, {18,20}, {19,21}, {26,28}, {27,29}, {17,25}, {22,30},     { 3, 4}, {11,12}, { 1, 8}, { 2,10}, { 5,13}, { 7,14}, {19,20}, {27,28}, {17,24}, {18,26}, {21,29}, {23,30},     { 3,11}, { 2, 8}, { 4,12}, { 7,13}, {19,27}, {18,24}, {20,28}, {23,29}, { 1,17}, {14,30},     { 3,10}, { 5,12}, {19,26}, {21,28}, { 1,16}, { 2,18}, {13,29}, {15,30},     { 3, 9}, { 6,12}, {19,25}, {22,28}, { 2,16}, {15,29},     { 3, 8}, { 7,12}, { 5, 9}, { 6,10}, {19,24}, {23,28}, {21,25}, {22,26},     { 4, 8}, { 7,11}, {20,24}, {23,27}, { 3,19}, {12,28},     { 5, 8}, { 7,10}, {21,24}, {23,26}, { 3,18}, { 4,20}, {11,27}, {13,28},     { 6, 8}, { 7, 9}, {22,24}, {23,25}, { 3,17}, { 5,21}, {10,26}, {14,28},     { 7, 8}, {23,24}, { 3,16}, { 5,20}, { 6,22}, { 9,25}, {11,26}, {15,28},     { 7,23}, { 6,20}, { 4,16}, { 5,17}, { 8,24}, {11,25}, {14,26}, {15,27},     { 7,22}, { 5,16}, { 6,18}, { 9,24}, {13,25}, {15,26},     { 7,21}, { 6,16}, {10,24}, {15,25},     { 7,20}, {11,24},     { 7,19}, {12,24},     { 7,18}, {13,24}, {11,19}, {12,20},     { 7,17}, {14,24}, {10,18}, {13,21},     { 7,16}, {15,24}, { 9,17}, {11,18}, {13,20}, {14,22},     { 8,16}, {11,17}, {15,23}, {14,20},     { 9,16}, {15,22}, {13,17}, {14,18},     {10,16}, {15,21},     {11,16}, {15,20},     {12,16}, {15,19},     {13,16}, {15,18},     {14,16}, {15,17},     {15,16}, }; typedef struct {     const unsigned int comparators;     const unsigned int (*pNetwork)[2]; } Network; #define elemof(ary) (sizeof(ary)/sizeof(ary[0])) #define NETWORK(n) {elemof(network##n), network##n} static const Network networks[] = {     {0, NULL},     {0, NULL},     NETWORK(02),     NETWORK(03),     NETWORK(04),     NETWORK(05),     NETWORK(06),     NETWORK(07),     NETWORK(08),     NETWORK(09),     NETWORK(10),     NETWORK(11),     NETWORK(12),     NETWORK(13),     NETWORK(14),     NETWORK(15),     NETWORK(16),     NETWORK(17),     NETWORK(18),     NETWORK(19),     NETWORK(20),     NETWORK(21),     NETWORK(22),     NETWORK(23),     NETWORK(24),     NETWORK(25),     NETWORK(26),     NETWORK(27),     NETWORK(28),     NETWORK(29),     NETWORK(30),     NETWORK(31),     NETWORK(32), }; #undef NETWORK static const size_t cutoff = elemof(networks); template inline void networkSort(Elem *p, size_t n) {     const unsigned int (* pNetwork)[2], (* pEnd)[2];     Elem *p0, *p1;     assert(n < elemof(networks));     pNetwork = networks[n].pNetwork;     pEnd = pNetwork + networks[n].comparators;     for(; pNetwork < pEnd; pNetwork++) {         p0 = p + (*pNetwork)[0];         p1 = p + (*pNetwork)[1];         if(*p1 < *p0) swap(p0, p1);     } }

## 图灵机vs数学家——图灵机计算能力的分析

（这是我2009年5月在繁星客栈上发表的，现稍加修改放在这里）

0.是否存在数学家可以做出判定的问题，不存在判定该问题的图灵机？
1.是否存在这样的通用判定图灵机，输入任何数学家可以判定的问题，该图灵机都能在有限步骤之内输出其判定结果，而不输出任何错误的判定结果？
2.是否存在这样的自动判定图灵机，自动尝试判定所有可能的判定问题，而对于其中任何一个数学家可以判定的问题，该图灵机都可以在有限步骤之内输出其判定结果，而不输出任何错误的判定结果？

1.H和X都不会对任何形式系统中的任何不可判定问题给出判定。
2.对于任何Lk中的任何【Pi】，无论【Pi】在Lk中是否可判定，都存在整数i’，使得【Pi’】==【Pi在Lk中可判定】，因此【Pi在Lk中可判定】这个问题迟早会被X枚举出来并尝试对之进行判定。只要【Pi在Lk中可判定】在某个形式系统Lk’中可判定，那么【Pi在Lk中可判定】的判定结果必然会在有限步骤内被X输出。
3.X在枚举Xn的过程中，许多Xn是根本不会停机的，而每次循环中X都必须单步执行所有尚未停机的Xn，因此X的效率会越来越低。但正如我们前面所讨论的，只要一个问题可以判定，X必然会在有限步骤内输出这个问题的判定，X的能力不会随着效率越来越低而变弱。如果实在觉得这种垃圾越来越多的系统很不舒服，那么还存在这样一个优化：每当某个Xn停机输出了某个问题A的判定结果，就检查A的内容是不是在断言另一个问题B不可判定，如果A有效断言出B不可判定，那么就将正在尝试判定B的图灵机从循环中删除。甚至还可以对B做个标记，在枚举新问题的时候，凡是将问题B作为子问题的问题，都将被直接跳过。不过这些优化其实没什么意义，我们的目的仅仅是讨论图灵机的计算能力，并不关心性能。

——————————————————————————————

## 从计算观点开始……（草稿）

• 孤立物理体系

————（可逆性、对称性、熵增、可观察量、规范……）

————（引入动机的数学模型，然后是偏好的评价函数，心理，行为，经济，博弈，生态系统，社会……）

• 开放的物理体系，相互作用

• 孤立机器

• 机器

1. 跟环境之间有一个分界线
2. 环境在边界上的状态作为机器输入可以改变机器状态
3. 机器在边界上的状态作为机器输出可以改变环境状态
4. 任何时刻其行为和内部状态的变迁完全由该时刻的内部状态和环境输入唯一决定

• 离散的孤立机器

• 离散的机器

• 有限状态机器

• 图灵机

## 吃苹果游戏和简单回合制游戏的通解

1. 确定游戏的完整状态（或者说局面）参数。比方说上面题目的完整状态参数就是(m,n,p)，m是整苹果的个数，n是半苹果的个数，p是此时由谁行动。
2. 游戏的行动规则确定了状态的迁移规则，或者说从某个状态出发可以到达哪些状态。比方说上面题目从(m,n,p)出发只能到达(m-1,n,~p)——吃一个整苹果、(m,n-1,~p)——吃一个半苹果、(m-1,n+1,~p)——吃半个整苹果，~p表示轮到对方行动。
3. 游戏的初始规则确定了状态空间的出发点。
4. 游戏的获胜规则确定了哪些状态是直接被判定为某一方获胜的。比方说上面问题中(0,0,p)意味着p获胜。在这些状态上，哪个玩家获胜，那么这个状态本身对于这个玩家来说就是有必胜策略的状态（废话，这个状态玩家p都已经获胜了那么p在该状态上当然是有必胜策略的）。
5. 最后一步就是从这些已知的必胜状态出发，递归地确定其他的状态是哪个玩家有必胜策略的状态。如果对于一个玩家来说，根据行动规则某个轮到自己行动的状态存在到达某个自己必胜的状态的行动选择，那么该点对于自己来说也是必胜状态，于是可以递归地将所有的状态都标记上是哪一方必胜，初始状态也会被标记，因此就可以确定初始状态哪一方有必胜策略。