design patterns - Algorithm problem- with the picture attached -


i attaching picture have shown diagram need check good/bad blocks. basically, have information of size of each block , number of rows , column. know if row has or odd number of blocks.

i need make cluster of 2 blocks , check if resultant block(with combination of 2) or bad. if 2 blocks good, resultant block , otherwise bad.

i need know algorithm of it.

if row has odd numbers of blocks, ignoring middle block , considering last blocks.

the diagram in shape of circle blocks on circumference ignored. so, have consider middle block shown in picture.

i need iterate on each row, make group of 2, find result. if row has odd number of blocks, ignore middle one, , make group of last 2 blocks @ corner.

the shape inside circle shown in picture, real figure.

i guess, have given enough information time.

note: in example, making group of two, need make group of 2, 3 or 4 blocks in row ,just generic case. if block in group bad,the whole group bad whether group of ,3, or 4.i need write code in visual basic language. size, no. of blocks in row shown in picture not real data.it example.

i have type of solution checks each block , surrounding block not right. can done in way:

here's solution:

if adding two, 1 badblock means both on either side bad leading 3 bad on

1) set nxn array of struct {bool incircle, badblock, badgroup;} incircle true if block in circle, badblock true if block bad on , badgroup false.

int length=2; (int i=0; i<n;i++)   for(int j=0; j<n;j++)      if(array[i,j].badblock){        for(int x=-length;x<=length;x++)            if(i+x>=0 , i+x<n , array[i+x,j].incircle) array[i+x,j].badgroup=true;         for(int y=-length;y<=length;y++)            if(j+y>=0 , j+y<n , array[i,j+y].incircle) array[i,j+y].badgroup=true;  } 

i know x , y co-ordinate of each block.

enter image description here

simple recursion do, pseudo-code:

groupsize = 2; bool calc(row, start, end) {    if (end-start <= groupsize -1) return true;    if (end - start < groupsize*2) //single group in middle, smaller 2 groups (calculate first group size)    {       bool result = true;       (i = start ; < groupsize; i++)       {          result = result && row[i];       }    }     else    {        return calc(row, start, start + groupsize) && calc(row,end-groupsize,end) && groupsize(row, start + groupsize,end-groupsize);     } } 

something that.
idea recursively calculate both sides of row , send middle more calculating.

recursion might simplest way (or not everyone), bu recursion can turned loop.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -