!!! modulus repeated in computed answer. !!! calculated answer v1: 0, v2: 2, v3: 2, moves: 2 !!! check answer v1: 0, v2: 1, v3: 2, moves: 2 Input vectors were v1: 2 v2: 2 v3: 2 !!! calculated move count larger than the check move count. !!! calculated answer v1: 0, v2: 1, v3: 2, moves: 3 !!! check answer v1: 0, v2: 1, v3: 2, moves: 2 Input vectors were v1: 2 v2: 2 v3: 2 2 2
!!! calculated move count larger than the check move count. !!! calculated answer v1: 0, v2: 0, v3: 4290699319, moves: 4290699688 !!! check answer v1: 0, v2: 1, v3: 2, moves: 0 Input vectors were v1: v2: v3:
| 000 | 100 | 200 | |
|---|---|---|---|
| 0 | 1 | 1 | |
| 10 | 1 | ||
| 20 | 3 | ||
| 30 | 1 | ||
| 40 | 3 | ||
| 50 | 5 | ||
| 60 | |||
| 70 | 2 | 3 | |
| 80 | |||
| 90 | 1 | 1 | |
| Totals | 3 | 18 | 1 |
| 000 | |
|---|---|
| 0 | |
| 10 | |
| 20 | |
| 30 | 1 |
| 40 | 3 |
| 50 | 2 |
| 60 | 6 |
| 70 | 2 |
| 80 | 5 |
| 90 | 3 |
| Totals | 22 |
| total | pages per procedure | ||||
|---|---|---|---|---|---|
| procs | 1 | 2 | 3 | 4 | 5 |
| 1 | 1 | ||||
| 1 | 1 | ||||
| 1 | 1 | ||||
| 1 | 1 | ||||
| 1 | 1 | ||||
| 1 | 1 | ||||
| 2 | 1 | 1 | |||
| 2 | 1 | 1 | |||
| 2 | 1 | 1 | |||
| 3 | 1 | 2 | |||
| 3 | 1 | 2 | |||
| 3 | 2 | 1 | |||
| 3 | 3 | ||||
| 3 | 3 | ||||
| 4 | 1 | 3 | |||
| 4 | 3 | 1 | |||
| 5 | 4 | 1 | |||
while r.v1 == max or r.v2 == max or r.v3 == max
if (*it).at_vector == 0)
and r.v1 == max
and mode_assigned[(*it).of_mod] == -1
mode_assigned[(*it).of_mod]=1
r.v1 = (*it).of_mod
it = v.erase(it)
else if (*it).at_vector == 1
and r.v2 == max
and mode_assigned[(*it).of_mod] == - 1
mode_assigned[(*it).of_mod]=1
r.v2 = (*it).of_mod
it = v.erase(it)
else if (*it).at_vector == 2
and r.v3 == max
and mode_assigned[(*it).of_mod] == -1
mode_assigned[(*it).of_mod]=1
r.v3=(*it).of_mod
it = v.erase(it)
else ++it
// Initialize mod_arr to zero. for (i = 0; i < THREE; i++) for (j = 0; j < THREE; j++) mod_arr[i][j] = ZERO;unsigned mod_arr[3][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };answer min_3sort(ivec iv1, ivec iv2, ivec iv3) // Implement the min_3sort function.answer min_3sort(ivec iv1, ivec iv2, ivec iv3) // Find the minimum 3-sort for the given vectors, // returning the minimum sort information.
static void assign(answer & local, ivec local_vec, unsigned & min) // Assigns values to local of type answer.static answer timed_run(min3sort_fun m3s, input_vectors vecs, time_t & et) // Run the 3-sorting procedure m3s against the given input // vectors, returning the result returned by the sort. // Also return in et the sorting time in usecs.
VT find_min_moves(VT * v_ary, int sz, int & mvs) { // Calculates the minimum move of the given 3 x 3 matrix.static void check_sort(answer & a, unsigned mods[], unsigned m_cnts[][3]) // Determine the number of moves in a sort in which all // residue mods[0] elements are moved to vector 1, all // residue mods[1] elements are moved to vector 2, and all // residue mods[2] elements are moved to vector 3. If the // sort is better than the results given in a, update a // with the new, better results. m_cnts[v][m] is the // number of elements with residue m in vector v.
unsignedmod_arr[3][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; // mod_cnts[v][m] = the number of elements // with residue m in vector v. unsigned mod_cnts[3][3] = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
} // end of if } // end of for } // end of while
for (i = 0; i < v.size(); i++)
if (v[i] % 3 == 0)
cnts[0]++
else if (v[i] % 3 == 1)
cnts[1]++
else
cnts[2]++
for (i = 0; i < v.size(); i++) cnts[v[i] % 3]++
void f(int i, int c[])
c[i % 3]++
void cnt_residues(ivec v, int cnts[3])
for_each(v.begin(), v.end(),
bind2nd(ptr_fun(f), cnts))
This page last modified on 13 November 2002.