Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This program finds draws for 6x6 Hip Game (http://delphiforfun.org/Programs/HIP.htm)
- //The base draw positions are:
- //0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 1
- //1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 0 0 0 0
- //0 0 1 0 0 1 1 0 1 0 0 1 1 0 1 0 0 1 0 1 1 0 1 1
- //1 0 0 1 0 1 1 0 0 1 0 0 1 0 0 1 0 1 1 1 0 1 1 0
- //0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1
- //1 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 1 0
- #include <stdio.h>
- #define SIZE 6
- #define TRUE 1
- int main()
- {
- int h[16][16];
- for(int i=0;i<=15;i++) for(int j=0;j<=15;j++) h[i][j]=-1;
- h[0][0]=0;
- int iter1=0;
- int iter2=1;
- int solutioncount=0;
- while(TRUE)
- {
- if(iter1==0 && iter2==0) break;
- h[iter1][iter2]++;
- if(h[iter1][iter2]>=2)
- {
- //go back
- h[iter1][iter2]=-1;
- iter2--;
- if(iter2<=-1)
- {
- iter1--;
- iter2=SIZE-1;
- }
- continue;
- }
- else
- {
- //check if valid
- //adjacent corner of square can be (a,b) satisfying:
- //a<=iter1, b<iter2
- //(iter2-b)+(iter1-a)<=iter1
- //(iter1-a)<=SIZE-1-iter2
- int valid=1;
- for(int a=0;a<=iter1;a++) for(int b=0;b<iter2;b++)
- {
- if(iter2-b+iter1-a>iter1 || iter1-a>=SIZE-iter2) continue;
- if(h[iter1][iter2]==h[a][b] && h[a][b]==h[a-(iter2-b)][b+(iter1-a)] && h[a][b]==h[iter1-(iter2-b)][iter2+(iter1-a)])
- valid=0;
- }
- if(!valid) continue;
- //go forward
- iter2++;
- if(iter2>=SIZE)
- if(iter1>=SIZE-1)
- {
- //solution
- //print those which have 18 1's
- int countones=0;
- for(int ii=0;ii<SIZE;ii++) for(int jj=0;jj<SIZE;jj++)
- {
- if(h[ii][jj]==1) countones++;
- }
- if(countones==SIZE*SIZE/2)
- {
- for(int i=0;i<SIZE;i++)
- {
- for(int j=0;j<SIZE;j++) printf("%d ",h[i][j]);
- printf("\n");
- }
- printf("\n");
- iter2--;
- solutioncount++;
- }
- else
- iter2--;
- }
- else
- {
- iter1++;
- iter2=0;
- }
- }
- }
- printf("Number of solutions: %d", solutioncount);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement