# populate array problem

• 11-22-2010
DaleZ
populate array problem
I'm working on creating a punnette square.

output array is a 2d 128 row by 14 (7 pairs) columns ( just for 1 side of the square).
source is a 1d 7 column array.

I have it hard coded atm but am looking for a solution to auto populate if I change the size of source (which would then change the output column size).

Code:

```      //dam[0]=den1; dam[1]=den2; dam[2]=da1; dam[3]=da2; dam[4]=db1; dam[5]=db; dam[6]=dc1; dam[7]=dc2;                 //dam[8] = dd1; dam[9] = dd2; dam[10] = de1; dam[11] = de2; dam[12]=dv1; dam[13]=dv2;                 int[] dam = damgtype.ToArray();                 // dam data array populate //                 // En                  |  A                |    B                |  C                  | D                  |  E                    | V //                 damdata[0, 0] = dam[0]; damdata[0, 1] = dam[2]; damdata[0, 2] = dam[4]; damdata[0, 3] = dam[6]; damdata[0, 4] = dam[8]; damdata[0, 5] = dam[10]; damdata[0, 6] = dam[12];                 damdata[1, 0] = dam[0]; damdata[1, 1] = dam[2]; damdata[1, 2] = dam[4]; damdata[1, 3] = dam[6]; damdata[1, 4] = dam[8]; damdata[1, 5] = dam[10]; damdata[1, 6] = dam[13];                 damdata[2, 0] = dam[0]; damdata[2, 1] = dam[2]; damdata[2, 2] = dam[4]; damdata[2, 3] = dam[6]; damdata[2, 4] = dam[8]; damdata[2, 5] = dam[11]; damdata[2, 6] = dam[12];                 damdata[3, 0] = dam[0]; damdata[3, 1] = dam[2]; damdata[3, 2] = dam[4]; damdata[3, 3] = dam[6]; damdata[3, 4] = dam[8]; damdata[3, 5] = dam[11]; damdata[3, 6] = dam[13];                 damdata[4, 0] = dam[0]; damdata[4, 1] = dam[2]; damdata[4, 2] = dam[4]; damdata[4, 3] = dam[6]; damdata[4, 4] = dam[9]; damdata[4, 5] = dam[10]; damdata[4, 6] = dam[12]; //d2e1v1                 damdata[5, 0] = dam[0]; damdata[5, 1] = dam[2]; damdata[5, 2] = dam[4]; damdata[5, 3] = dam[6]; damdata[5, 4] = dam[9]; damdata[5, 5] = dam[10]; damdata[5, 6] = dam[13];                 damdata[6, 0] = dam[0]; damdata[6, 1] = dam[2]; damdata[6, 2] = dam[4]; damdata[6, 3] = dam[6]; damdata[6, 4] = dam[9]; damdata[6, 5] = dam[11]; damdata[6, 6] = dam[12]; //d2e2v1                 damdata[7, 0] = dam[0]; damdata[7, 1] = dam[2]; damdata[7, 2] = dam[4]; damdata[7, 3] = dam[6]; damdata[7, 4] = dam[9]; damdata[7, 5] = dam[11]; damdata[7, 6] = dam[13];                 damdata[8, 0] = dam[0]; damdata[8, 1] = dam[2]; damdata[8, 2] = dam[4]; damdata[8, 3] = dam[7]; damdata[8, 4] = dam[8]; damdata[8, 5] = dam[10]; damdata[8, 6] = dam[12]; //c2d1e1v1                 damdata[9, 0] = dam[0]; damdata[9, 1] = dam[2]; damdata[9, 2] = dam[4]; damdata[9, 3] = dam[7]; damdata[9, 4] = dam[8]; damdata[9, 5] = dam[10]; damdata[9, 6] = dam[13];                 damdata[10, 0] = dam[0]; damdata[10, 1] = dam[2]; damdata[10, 2] = dam[4]; damdata[10, 3] = dam[7]; damdata[10, 4] = dam[8]; damdata[10, 5] = dam[11]; damdata[10, 6] = dam[12]; //c2d1e2v1                 damdata[11, 0] = dam[0]; damdata[11, 1] = dam[2]; damdata[11, 2] = dam[4]; damdata[11, 3] = dam[7]; damdata[11, 4] = dam[8]; damdata[11, 5] = dam[11]; damdata[11, 6] = dam[13];                 damdata[12, 0] = dam[0]; damdata[12, 1] = dam[2]; damdata[12, 2] = dam[4]; damdata[12, 3] = dam[7]; damdata[12, 4] = dam[9]; damdata[12, 5] = dam[10]; damdata[12, 6] = dam[12]; //c2d2e1v1                 damdata[13, 0] = dam[0]; damdata[13, 1] = dam[2]; damdata[13, 2] = dam[4]; damdata[13, 3] = dam[7]; damdata[13, 4] = dam[9]; damdata[13, 5] = dam[10]; damdata[13, 6] = dam[13];                 damdata[14, 0] = dam[0]; damdata[14, 1] = dam[2]; damdata[14, 2] = dam[4]; damdata[14, 3] = dam[7]; damdata[14, 4] = dam[9]; damdata[14, 5] = dam[11]; damdata[14, 6] = dam[12]; //c2d2e2v1                 damdata[15, 0] = dam[0]; damdata[15, 1] = dam[2]; damdata[15, 2] = dam[4]; damdata[15, 3] = dam[7]; damdata[15, 4] = dam[9]; damdata[15, 5] = dam[11]; damdata[15, 6] = dam[13];                 damdata[16, 0] = dam[0]; damdata[16, 1] = dam[2]; damdata[16, 2] = dam[5]; damdata[16, 3] = dam[6]; damdata[16, 4] = dam[8]; damdata[16, 5] = dam[10]; damdata[16, 6] = dam[12]; //b2c1d1e1v1                 damdata[17, 0] = dam[0]; damdata[17, 1] = dam[2]; damdata[17, 2] = dam[5]; damdata[17, 3] = dam[6]; damdata[17, 4] = dam[8]; damdata[17, 5] = dam[10]; damdata[17, 6] = dam[13];                 damdata[18, 0] = dam[0]; damdata[18, 1] = dam[2]; damdata[18, 2] = dam[5]; damdata[18, 3] = dam[6]; damdata[18, 4] = dam[8]; damdata[18, 5] = dam[11]; damdata[18, 6] = dam[12]; //b2c1d1e2v1                 damdata[19, 0] = dam[0]; damdata[19, 1] = dam[2]; damdata[19, 2] = dam[5]; damdata[19, 3] = dam[6]; damdata[19, 4] = dam[8]; damdata[19, 5] = dam[11]; damdata[19, 6] = dam[13];                 damdata[20, 0] = dam[0]; damdata[20, 1] = dam[2]; damdata[20, 2] = dam[5]; damdata[20, 3] = dam[6]; damdata[20, 4] = dam[9]; damdata[20, 5] = dam[10]; damdata[20, 6] = dam[12]; //b2c1d2e1v1                 damdata[21, 0] = dam[0]; damdata[21, 1] = dam[2]; damdata[21, 2] = dam[5]; damdata[21, 3] = dam[6]; damdata[21, 4] = dam[9]; damdata[21, 5] = dam[10]; damdata[21, 6] = dam[13];                 damdata[22, 0] = dam[0]; damdata[22, 1] = dam[2]; damdata[22, 2] = dam[5]; damdata[22, 3] = dam[6]; damdata[22, 4] = dam[9]; damdata[22, 5] = dam[11]; damdata[22, 6] = dam[12]; //b2c1d2e2v1                 damdata[23, 0] = dam[0]; damdata[23, 1] = dam[2]; damdata[23, 2] = dam[5]; damdata[23, 3] = dam[6]; damdata[23, 4] = dam[9]; damdata[23, 5] = dam[11]; damdata[23, 6] = dam[13];                 damdata[24, 0] = dam[0]; damdata[24, 1] = dam[2]; damdata[24, 2] = dam[5]; damdata[24, 3] = dam[7]; damdata[24, 4] = dam[8]; damdata[24, 5] = dam[10]; damdata[24, 6] = dam[12]; //b2c2d1e1v1                 damdata[25, 0] = dam[0]; damdata[25, 1] = dam[2]; damdata[25, 2] = dam[5]; damdata[25, 3] = dam[7]; damdata[25, 4] = dam[8]; damdata[25, 5] = dam[10]; damdata[25, 6] = dam[13];                 damdata[26, 0] = dam[0]; damdata[26, 1] = dam[2]; damdata[26, 2] = dam[5]; damdata[26, 3] = dam[7]; damdata[26, 4] = dam[8]; damdata[26, 5] = dam[11]; damdata[26, 6] = dam[12];                 damdata[27, 0] = dam[0]; damdata[27, 1] = dam[2]; damdata[27, 2] = dam[5]; damdata[27, 3] = dam[7]; damdata[27, 4] = dam[8]; damdata[27, 5] = dam[11]; damdata[27, 6] = dam[13];                 damdata[28, 0] = dam[0]; damdata[28, 1] = dam[2]; damdata[28, 2] = dam[5]; damdata[28, 3] = dam[7]; damdata[28, 4] = dam[9]; damdata[28, 5] = dam[10]; damdata[28, 6] = dam[12]; // b2c2d2e1v1                 damdata[29, 0] = dam[0]; damdata[29, 1] = dam[2]; damdata[29, 2] = dam[5]; damdata[29, 3] = dam[7]; damdata[29, 4] = dam[9]; damdata[29, 5] = dam[10]; damdata[29, 6] = dam[13];```
• 11-22-2010
VirtualAce
After finding out what punnete square is (thank you Google), it looks fairly simple to code.

Remove your hardcoded 'stuff'. I could tell you how to do it but that really wouldn't help you. Try it out using some loops or other data structures and post your attempt here. From there myself and perhaps more people can guide you in various directions based on your efforts.
• 11-23-2010
DaleZ
I took another crack at it trying various methods. This time I tried it from left to right instead of right to left.

this is what I came up with:
Code:

```     int den = 1; int da = 1; int db = 1; int dc = 1; int dd = 1; int de = 1; int dv = 0; int x = 0;                 do                 {                     // Broken                     if (den <= 64)                     { damdata[x, 0] = dam[0]; }                     else { damdata[x, 0] = dam[1]; }                     {                         // Agouti                         if (da <= 32)                         { damdata[x, 1] = dam[2]; }                         else { damdata[x, 1] = dam[3]; }                         if (da == 64) // reset Agouti counter                         { da = 1; }                     }                     {                         // Brown                         if (db <= 16)                         { damdata[x, 2] = dam[4]; }                         else { damdata[x, 2] = dam[5]; }                         if (db == 32) // reset Brown counter                         { db = 1; }                     }                     {                         // Color                         if (dc <= 8)                         { damdata[x, 3] = dam[6]; }                         else { damdata[x, 3] = dam[7]; }                         if (dc == 16) // reset Color counter                         { dc = 1; }                     }                     {                         // Dilute                         if (dd <= 4)                         { damdata[x, 4] = dam[8]; }                         else { damdata[x, 4] = dam[9]; }                         if (dd == 8) // reset Dilute counter                         { dd = 1; }                     }                     {                         // Extension                         if (de <= 2)                         { damdata[x, 5] = dam[10]; }                         else { damdata[x, 5] = dam[11]; }                         if (de == 4) //reset Extension counter                         { de = 1; }                     }                     {                         // Vienna                         if (dv == 1)                         { damdata[x, 6] = dam[12]; }                         else { damdata[x, 5] = dam[13]; }                         if (dv == 2) // reset Vienna counter                         { dv = 1; }                     }                     x++; den++; da++; db++; dc++; dd++; de++; dv++;                 } while (x < 127);```
Is there a more efficient way to do this?

below is a description of the problem:
Dam contains EnenAaBbCcDdEeVv
What I need damdata to contain is:
EnABCDEV
ENABCDEv
ENABCDeV
EnABCDev
EnABCdEV
ect.....
• 11-24-2010
VirtualAce
I guess I'm a bit lost but let's break the problem down to something much simpler.

Excuse my terrible ASCII art grid:

____A___B___C___D____AB