C# 2X8 ARRAY Placing Similar Items -


i have 5 items: a,b,c,d,e

i need assign them 2x8 array, need place similar items far possible , if possible simetric place

for example if amount of each items contain following

a= 2, b= 2, c=3, d=4, e=5

manually can following

e c d b c e d

d e c b d e e

i tried many thing random, program hangs in loop

could give me idea

thanks

    private void button2_click_1(object sender, eventargs e)     {         random rnd = new random();           richtextbox3.text = "";          // have 5 kind of material, each of them have following amount:         // type a=2         // type b=2         // type c=3         // type d=4         // type e=5         int[] materials = { 2, 2, 3, 4, 5 };          int xa = materials[0];  // material amount         int xb = materials[1];  // material b amount         int xc = materials[2];         int xd = materials[3];         int xe = materials[4];          //  need place them in 2 row * 8 column         // when doing assignment should place similar materials far away possible         // possible symetric order          string[,] array = new string[2,8];         array.clear(array, 0, array.length);          array[0, 0] = "e"; // beginnig assigned (0,0) biggest material(e)         xe = xe - 1;          array[1, 0] = "d";// second row (1,0) second biggest material (d)         xd = xd - 1;           // first row          (int j = 1; j < 8; j++) // used first column d , e material             {                 int random = rnd.next(0, 5); // randomly choose 1 of material                  // if column blank (not assigned before ,                 // if random material 0 (a type) , amount of not 0                 // , previous column not assigned type                 if (array[0,j]=="" && random == 0 && xa != 0 && array[0,j-1]!="a")                 {                          array[0,j] = "a"; // assign column                         xa = xa - 1; // reduce amount                           richtextbox3.text += "a"; // write "a" in text box                         richtextbox3.text += " ";                   }                  // b type condition                 else if (array[0,j]=="" && random == 1 && xb != 0 && array[0,j-1]!="b")                 {                          array[0,j] = "b"; // assign b column                         xb = xb - 1; // reduce b amount                           richtextbox3.text += "b"; // write "b" in text box                         richtextbox3.text += " ";                   }                 // c type condition                 else if (array[0, j] == "" && random == 2 && xc != 0 && array[0, j - 1] != "c")                 {                      array[0, j] = "c"; // assign c column                     xc = xc - 1; // reduce c amount                       richtextbox3.text += "c"; // write "c" in text box                     richtextbox3.text += " ";                  }                       // d type condition                 else if (array[0, j] == "" && random == 3 && xd != 0 && array[0, j - 1] != "d")                 {                      array[0, j] = "d"; // assign d column                     xd = xd - 1; // reduce d amount                       richtextbox3.text += "d"; // write "d" in text box                     richtextbox3.text += " ";                  }                 // e type condition                 else if (array[0, j] == "" && random == 4 && xd != 0 && array[0, j - 1] != "e")                 {                      array[0, j] = "e"; // assign e column                     xe = xe - 1; // reduce e amount                       richtextbox3.text += "e"; // write "c" in text box                     richtextbox3.text += " ";                  }                     else j = j - 1; // if above not true try again             }         } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -