Here it is, but I wrote a version which is more than 10 times faster. I just solved the problem of 4 knights on 10*10,11*11, 12*12 and 13*13 boards ! 10x10: sol 1 with 16 knights . . . x . . . . . . . x . . . x . . . . . . x x x . . . . . x . x . x . x . . . . . x x x . . . . . . x . . . x . . . . . . . x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sol 2 with 16 knights . . . . x . . . . . . . x . . . x . . . . . . x x x . . . . . x . x . x . x . . . . . x x x . . . . . . x . . . x . . . . . . . x . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . sol 3 with 16 knights . . . . . . . . . . . . . . x . . . . . . . x . . . x . . . . . . x x x . . . . . x . x . x . x . . . . . x x x . . . . . . x . . . x . . . . . . . x . . . . . . . . . . . . . . . . . . . . . . . . . 11x11: sol 1 with 36 knights . . . x . . . . . . . . x . . . x . . . . . . . x x x . . x . . . x . x . x x . . . x . . . x x . x . x x . . . x . x . . . x x . x . . . x . x x x x x . . . . . . x x x . x . . . . . x . . x x . . . . . . . . x . . . . . . . . . . . . . . . sol 2 with 36 knights . . . x . . . . . . . . x . . . x . . . . . . . x x x . . . . . . x . x . x x x . . . . . . x x . . . . x . . . x . x x . x x . . . . . . . . . x x . x . . . x . x x x x x . . . . . . x x x . x . . . . . x . . x x . . . . . . . . x . . . . . sol 3 with 36 knights . . . . x . . . . . . . . x x . . x . . . . . x . x x x . . . . . . x x x x x . x . . . x . x x . . . x . x . . . x x . x . x x . . . x . . . x x . x . x . . . x . . x x x . . . . . . . x . . . x . . . . . . . . x . . . . . . . . . . . . . . sol 4 with 36 knights . . . . x . . . . . . . . x x . . x . . . . . x . x x x . . . . . . x x x x x . x . . . x . x x . . . . . . . . . x x . x x . x . . . x . . . . x x . . . . . . x x x . x . x . . . . . . x x x . . . . . . . x . . . x . . . . . . . . x . . . . sol 5 with 36 knights . . . . x . . . . . . . . x . . . x . . . . . . . x x x . . . . . . x . x . x x x . . . . . . x x . . . . x . . . x . x x . x x . . . . . . . . . x x . x . . . x . x x x x x . . . . . . x x x . x . . . . . x . . x x . . . . . . . . x . . . . 12x12: sol 1 with 56 knights (better solution below) . . . x . . . . x . . . . x . . . x x . . . x . . . x x x . . x x x . . x . x . x . . x . x . x . . x x x . . x x x . . . x . . . x x . . . x . . x . . . x x . . . x . . . x x x . . x x x . . x . x . x . . x . x . x . . x x x . . x x x . . . x . . . x x . . . x . . . . x . . . . x . . . sol 1 with 68 knights . . . . x . . x . . . . . . x x . x x . x x . . . x . x x x x x x . x . . x x x x . . x x x x . x . x x . . . . x x . x . x x . . . . . . x x . . x x . . . . . . x x . x . x x . . . . x x . x . x x x x . . x x x x . . x . x x x x x x . x . . . x x . x x . x x . . . . . . x . . x . . . . 13x13: sol 1 with 80 knights . . . x . . x . . x . . . . x . . x x x x x . . x . . . x x x x . x x x x . . x . x x . x x x . x x . x . x x . . . . . . . x x . . x x x . . . . . x x x . x x . x . . . . . x . x x . x x x . . . . . x x x . . x x . . . . . . . x x . x . x x . x x x . x x . x . . x x x x . x x x x . . . x . . x x x x x . . x . . . . x . . x . . x . . . On the 9x9 board, you can place: 32 knights, every attacking exactly one knight (19715 solutions at least) 40 knights, every attacking exactly 2 knights (664 solutions) 36 knights, every attacking exactly 3 knights (unique, below) 16 knights, every attacking exactly 4 knights sol 1 with 36 knights . x . . . x x . . . . x x x x . . . x . x x x x x x . . x . . . . x . . . x x . . . x x . . . x . . . . x . . x x x x x x . x . . . x x x x . . . . x x . . . x . On the 10x10, you can place: 48 knights, every attacking exactly 2 knights (>=13 solutions) 48 knights, every attacking exactly 3 knights (4 solutions) 16 knights, every attacking exactly 4 knights JC ----- Original Message ----- From: "Ed Pegg Jr" To: "Jean-Charles Meyrignac" Sent: Friday, June 06, 2003 4:38 PM Subject: Re: Knights > > Could you send me the corrected Knights program? > > --Ed > > // Placement de cavaliers sur un echiquier N*N, de telle sorte que // chaque cavalier soit en prise avec exactement P autres cavaliers. // // EB Mai 97 #include #include const int N=9; const int M=N+4; int P; struct ValCase { int np; // Nombre de pieces menacant la case int c; // C=0 : case libre // C=1 : case occupee par un cavalier }; struct ValCavalier { int c; // Position du cavalier }; // Differences d'indices avec les voisins dans le tableau const int Voisin[8]={-2*M-1,-2*M+1,-M-2,-M+2,M-2,M+2,2*M-1,2*M+1}; ValCase E[M*M]; // L'echiquier (entoure de 2 rangees vides) ValCavalier C[N*N]; int NC; // Nombre de cavaliers poses int NSOL; // Nombre de solutions avec NCMAX int NCMAX; // Nombre maxi de cavaliers dans solution int poseCavalier(int c) // Essaie de poser un cavalier dans la case C. // Renvoie 1 si le cavalier est pose. { int i; if (E[c].np>P) return 0; for (i=0;i<8;i++) if (E[c+Voisin[i]].c && E[c+Voisin[i]].np>=P) return 0; E[c].c=1; for (i=0;i<8;i++) E[c+Voisin[i]].np++; C[NC].c=c; NC++; return 1; } void retireCavalier(int c) // Retire le cavalier pose dans la case C. { int i; E[c].c=0; for (i=0;i<8;i++) E[c+Voisin[i]].np--; NC--; } void explore(int x,int y) { int xx,yy,c,i; if (y==N) { if (NCNCMAX) { NCMAX=NC;NSOL=0; } NSOL++;printf("Solution SOL=%d N=%d P=%d (NC=%d)\n",NSOL,N,P,NC); for (yy=0;yy=3) { c=2+M*(y-1); // 3 lignes plus haut, plus rien ne // peut changer, on peut donc deja regarder // si on peut avoir une solution for (i=0;i8) { fprintf(stderr,"P doit etre dans 0..8 (%d)\n",P);exit(1); } printf("Probleme des cavaliers : N=%d P=%d\n",N,P); NSOL=NC=NCMAX=0; for (i=0;i The Pythag, a {3,4}+{0,5) leaper, might also be an interesting piece to check. > I modified my program to search for self-attacking Pythags on the chessboard. You can place 32 non-attacking Pythags: x . x . x . x . . x . x . x . x x . x . x . x . . x . x . x . x x . x . x . x . . x . x . x . x x . x . x . x . . x . x . x . x You can also place 32 Pythags, with every Pythag attacking exactly one other Pythag: x x . . x x . . . . x x . . x x x x . . x x . . . . x x . . x x x x . . x x . . . . x x . . x x x x . . x x . . . . x x . . x x (solution is unique) You can also place 32 Pythags, so that every Pythag attacks exactly 2 other Pythags: sol 1 with 32 Pythags x x x x x x x x . . . . . . . . x x x x x x x x . . . . . . . . x x x x x x x x . . . . . . . . x x x x x x x x . . . . . . . . sol 2 with 32 Pythags x x x x x x x x . . . . . . . . x x x x . x x x . . . x . x . . x x x x . x x x . . . . . . . . x x x x x x x x . . . . . . . . sol 3 with 32 Pythags x x x x x x x x . . . . . . . . x x x . x x x x . . x . x . . . x x x . x x x x . . . . . . . . x x x x x x x x . . . . . . . . sol 4 with 32 Pythags x x x x x x x x . . . . . . . . x x x . . x x x . . x x x x . . x x x . . x x x . . . . . . . . x x x x x x x x . . . . . . . . sol 5 with 32 Pythags x x x x x x x x . . . . . . . . x . x x x x . x x . . . . . . x . x x x x x x . . . . . . . . . x x x x x x x x . x . . . . x . (5 solutions, perhaps less without reflection/rotations) Also, you can place 32 Pythags, so that every attacks 3 others: x x x x x x x x . . . . . . . . . . . . . . . . x x x x x x x x x x x x x x x x . . . . . . . . . . . . . . . . x x x x x x x x There is a unique solution so that every Pythag attacks 4 others. Attached, the 2 sources I used to find that. You must first run GenKim.c, which will create a file called GEN.H. Modify NX, NY and LEAPER NX=width of the board NY=height of the board LEAPER=0 for standard knight, 1 for Pythag Then, compile MAIN.C Modify P to the number of attacked pieces. JC Plain Text Attachment [ Save to my Yahoo! Briefcase | Download File ] /* program to solve the attacking knights on large boards ! - remove symmetries !!! if (!board[0]) -> board[nx-1]=0, etc... */ #include #define NX 8 #define NY 8 #define LEAPER 1 //0=knight, 1=Pytag (0,5)/(3,4) #if LEAPER==0 #define NBDIRECTIONS 8 #else #define NBDIRECTIONS 12 #endif int direction[NBDIRECTIONS*2]= { #if LEAPER==0 -1,-2, +1,-2, -2,-1, +2,-1, -2,+1, +2,+1, -1,+2, +1,+2, #else 0,-5, -3,-4, +3,-4, -4,-3, +4,-3, -5,0, 5,0, -4,+3, +4,+3, -3,+4, +3,+4, 0,5, #endif }; FILE *stream; int Neighbour[NX*NY][NBDIRECTIONS]; char *GetName(int n) { static char name[100]; name[0]=n/NX+'a'; sprintf(name+1, "%d", (n%NX)+1); return name; } int Rotation(int n, int rot) { int x, y; x = n%NX; y = n/NX; switch(rot) { case 0: return y*NX+x; case 1: return (NY-1-y)*NX+x; case 2: return y*NX+(NX-1-x); case 3: return (NY-1-y)*NX+(NX-1-x); #if NX==NY case 4: return x*NX+y; case 5: return (NY-1-x)*NX+y; case 6: return x*NX+(NX-1-y); case 7: return (NY-1-x)*NX+(NX-1-y); #endif } return y*NX+x; } int Symetries[NX*NY]; int NbSym=0; void Gen() { int x, y, o, d; int s, r, bs; //generate the Neighbours fprintf(stream,"int Attack[%d];\n", NX*NY); fprintf(stream,"int Board[%d];\n", NX*NY); fprintf(stream,"int NCMAX=0;\n"); fprintf(stream,"int NBSOL=0;\n"); fprintf(stream,"int Cut=0;\n"); fprintf(stream,"void Solution(int NC)\n"); fprintf(stream,"{\n"); fprintf(stream,"\tint x;\n"); fprintf(stream,"\tFILE *out;\n"); fprintf(stream,"\tif (NC < NCMAX) return;\n"); fprintf(stream,"\tfor (x=0;x<%d;++x)\n", NX*NY); fprintf(stream,"\t\tif (Board[x]&&Attack[x]!=P) return;\n"); fprintf(stream,"\tif (NC > NCMAX) {NCMAX=NC;NBSOL=0;}\n"); fprintf(stream,"\tout=fopen(\"RES%d-%d.TXT\", \"at\");\n", NX, NY); fprintf(stream,"\tprintf(\"sol %%d with %%d knights\\n\", ++NBSOL, NCMAX);\n"); fprintf(stream,"\tfprintf(out, \"sol %%d with %%d knights\\n\", NBSOL, NCMAX);\n"); fprintf(stream,"\tfor (x=0;x<%d;++x)\n", NX*NY); fprintf(stream,"\t{\n"); fprintf(stream,"\t\tprintf(\"%%s \", Board[x] ? \"x\":\".\");\n"); fprintf(stream,"\t\tfprintf(out, \"%%s \", Board[x] ? \"x\":\".\");\n"); fprintf(stream,"\t\tif ((x%%%d)==%d) {printf(\"\\n\");fprintf(out,\"\\n\");}\n", NX, NX-1); fprintf(stream,"\t}\n"); fprintf(stream,"\tfclose(out);\n", NX, NY); fprintf(stream,"}\n"); for (x=0;x= NX || y2 >= NY) continue; Neighbour[y*NX+x][n]=y2*NX+x2; ++n; } if (n < NBDIRECTIONS) { Neighbour[y*NX+x][n]=-1; } } } // debug /* for (y=0;y= NX+NX+2) { o=x-(NX+NX+2); fprintf(stream,"\tif (Board[%d] && Attack[%d]!=P) return;\n", o, o); } #else if (x >= NX*5-1) { o=x-(NX*5-1); fprintf(stream,"\tif (Board[%d] && Attack[%d]!=P) return;\n", o, o); } #endif // computes the symmetries bs=x; for (r=0;r<8;++r) { s=Rotation(x, r); if (Symetries[s]>Symetries[bs]) { bs = s; } } fprintf(stream,"\t"); if (Symetries[bs]) { fprintf(stream,"if (Cut<%d) ", Symetries[bs]); } fprintf(stream,"if (Attack[%d]<=P)\n", x); fprintf(stream,"\t{\n"); fprintf(stream,"\t\t"); for (d=0;d x) break; fprintf(stream,"if (!Board[%d] || Attack[%d] #include #define P 4 #include "gen.h" #define PRIORITY 8 int main(void) { SetPriorityClass(GetCurrentProcess (), (PRIORITY < 2 || PRIORITY > 6) ? NORMAL_PRIORITY_CLASS : IDLE_PRIORITY_CLASS); SetThreadPriority(GetCurrentThread(), (PRIORITY == 1) ? THREAD_PRIORITY_IDLE : (PRIORITY == 2 || PRIORITY == 7) ? THREAD_PRIORITY_LOWEST : (PRIORITY == 3 || PRIORITY == 8) ? THREAD_PRIORITY_BELOW_NORMAL : (PRIORITY == 4 || PRIORITY == 9) ? THREAD_PRIORITY_NORMAL : (PRIORITY == 5 || PRIORITY == 10) ? THREAD_PRIORITY_ABOVE_NORMAL : THREAD_PRIORITY_HIGHEST); a1(0); return 0; } ---------------------------- Ed, Here is my arrangement whereby 32 knights on a standard board each attack only one other knight. NN__NNNN NN__NNNN NN______ NN______ ______NN ______NN NNNN__NN NNNN__NN Mike Malak -------------------------