ubuntu - Efficient way to draw 3! ( 6 times) three shapes in C -


i want draw combinations (3! = 6) of 3 shapes , in 1 row : empty cell , x , or rectangle .

the current code :

for empty cell :

void drawemptycell() {      printf("||||||||||||||||||||||||||\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("||||||||||||||||||||||||||\n");  } 

for cell rectangle :

void drawcellwithrectangle() {      printf("||||||||||||||||||||||||||\n");     printf("|                        |\n");     printf("|                        |\n");     printf("|     **************     |\n");     printf("|     *            *     |\n");     printf("|     *            *     |\n");     printf("|     *            *     |\n");     printf("|     *            *     |\n");     printf("|     *            *     |\n");     printf("|     **************     |\n");     printf("|                        |\n");     printf("|                        |\n");     printf("||||||||||||||||||||||||||\n");  } 

and cell x :

void drawcellwithx() {      printf("||||||||||||||||||||||||||\n");     printf("|                        |\n");     printf("|   *               *    |\n");     printf("|     *           *      |\n");     printf("|       *       *        |\n");     printf("|         *   *          |\n");     printf("|           *            |\n");     printf("|         *   *          |\n");     printf("|       *       *        |\n");     printf("|     *           *      |\n");     printf("|   *               *    |\n");     printf("|                        |\n");     printf("||||||||||||||||||||||||||\n");  } 

i can use brute force way , take 6 options , example :

void drawoption1() {     // empty , rectangle , x      printf("||||||||||||||||||||||||||");printf("||||||||||||||||||||||||||");printf("||||||||||||||||||||||||||\n");     printf("|                        |");printf("|                        |");printf("|                        |\n");     printf("|                        |");printf("|                        |");printf("|   *               *    |\n");     printf("|                        |");printf("|     **************     |");printf("|     *           *      |\n");     printf("|                        |");printf("|     *            *     |");printf("|       *       *        |\n");     printf("|                        |");printf("|     *            *     |");printf("|         *   *          |\n");     printf("|                        |");printf("|     *            *     |");printf("|           *            |\n");     printf("|                        |");printf("|     *            *     |");printf("|         *   *          |\n");     printf("|                        |");printf("|     *            *     |");printf("|       *       *        |\n");     printf("|                        |");printf("|     **************     |");printf("|     *           *      |\n");     printf("|                        |");printf("|                        |");printf("|   *               *    |\n");     printf("|                        |");printf("|                        |");printf("|                        |\n");     printf("||||||||||||||||||||||||||");printf("||||||||||||||||||||||||||");printf("||||||||||||||||||||||||||\n");  } 

but i'm looking else , without brute force way .

any suggestions appreciated .

a approach put shapes string array. appropriate algorithm draw them

something following job. hope idea

char* x[] = {    "||||||||||||||||||||||||||",   "|                        |",   "|   *               *    |",   "|     *           *      |",   "|       *       *        |",   "|         *   *          |",   "|           *            |",   "|         *   *          |",   "|       *       *        |",   "|     *           *      |",   "|   *               *    |",   "|                        |",   "||||||||||||||||||||||||||"}; char* o[] .. char* empty[] .. .. output (" xo"); .. void output (const char* pout) {   // assert (sizeof(x) == sizeof(o));   // assert (sizeof(x) == sizeof(empty));   int i, j;    (i = 0; < sizeof(o) / sizeof(o[0]); ++) {     const char* c = pout;     while (*c != 0) {       switch (*c ++) {       case 'x':        printf (x[i]); break;        case 'o':        printf (o[i]); break;       default:           printf (empty[i]); break;       }     }     printf ("\n");   } } 

obviously x,o, empty required hold same number of line.

now in c, no compiled yet, may have errors


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

jquery - How can I dynamically add a browser tab? -