Problem description
Chinese chess inside the "will" and "handsome" each stay in their own nine lattice, one step can only move sideways or vertically, and both sides can not meet (can not be in the same vertical line). In the aftermath, some people will use this rule to get out of the wonderful kill trick. Assuming that one party's "will" is a, the other party's "handsome" is B, and now the two sides can appear in all legal positions, the required variable can only be saved with a single byte.
My solution.
#include <stdio.h>int main (void) {unsigned char chpos = 0x11;for (; (Chpos & 0x0f) <= 9; Chpos + = 0x01) {for (; (Chpos >> 4) <= 9; Chpos + = 0x10) {if (((Chpos & 0x0f)-1)% 3 = = ((((Chpos >> 4) 1)% 3)) continue;printf ("B = (%c,%d) A = (% C,%d) \ n ", ' d ' + ((Chpos & 0x0f)-1)% 3, 1 + ((Chpos & 0x0f)-1)/3, ' d ' + ((Chpos >> 4)-1)% 3 , 8 + ((Chpos >> 4)-1)/3);} Chpos &= 0x0f;chpos |= 0x10;} return 0;}
As long as a byte, generals can only be moved at 9 points, so the first four bits represent the location of the handsome (1~9), the last four digits, then 3 is the column number, except 3 is the line number, as long as the column number is different can be guaranteed.
"The beauty of programming" Chinese Chess Generals problem