//949 //1047 #include #include using namespace std; const int SIZE=6; //grid size const int PATTERN=9; //pattern size struct gridPos { void set(int a,int b){x=a;y=b;} int x,y; }; int rotate(int pos, int times=0) { //90 counter-clockwise simulation //convert from string to grid coordinates int x=pos/SIZE; int y=pos%SIZE; //rotate grid gridPos grid; if (times==1) grid.set(y,SIZE-1-x); else if (times==2) grid.set(SIZE-1-x,SIZE-1-y); else if (times==3) grid.set(SIZE-1-y,x); else grid.set(x,y); //back to string coordinates return grid.x*SIZE+grid.y; } int main() { string code; int pattern[9]={1,3,8,14,10,17,22,29,35}; //pattern while (cin>>code && code.compare("0")!=0) { for (int rotation=0;rotation<4;rotation++) //second, we rotate each pattern for (int i=0;i