@*Intro. Make {\mc DLX} data to pack a given set of words into a Torto' puzzle. In other words, we want to create a $6\times3$ array of characters, where each of the given words can be found by tracing a noncrossing king path. I've tried to allow arrays of sizes that differ from the $6\times3$ default. But I haven't really tested that. I learned the basic idea of this program from Ricardo Bittencourt in January 2019. (My first attempt was much, much slower.) (My second attempt was better but still not close.) (So I've pretty much adopted his ideas, lock, stock, and barrel. They have an appealing symmetry.) In order to save a factor of two, I make the middle transition of the first word start in the top three rows. Furthermore, in order to save another factor of (nearly) two, I don't allow it to start in the rightmost column; and if it starts in the middle column, I don't allow it to move right. It seems likely that best results will be obtained if the first word is the longest, and if it has lots of characters that aren't shared with other words. The reason is that the middle of this word will tend to be placed first, and many other possibilities will be blocked early on. @d rows 6 @d cols 3 /* you must change |encode| if |rows*cols>26| */ @d encode(k) ((k)<10? '0'+(k): (k)<36? 'a'+(k)-10: (k)<62? 'A'+(k)-36: '?') @d encodeij(i,j) encode(10+(i)*cols+(j)) @c #include #include main (int argc,char*argv[]) { register int i,j,k,l,ll,flag; @; @; for (k=1;k; } @ @= if (argc==1) { fprintf(stderr,"Usage: %s word0 word1 ...\n", argv[0]); exit(-1); } printf("| %s",argv[0]); for (k=1;k$j$} and \.{$k$\char\<$x$}, which map'' the path for word~$k$. This path is a one-to-one correspondence between the indices $0$ thru $l-1$ and the cells where the word is found. The color of \.{$k$\char\>$j$} is $x$ if and only if the color of \.{$k$\char\<$x$} is $j$. And there also are secondary items \.{$k$/$y$}, where $y$ is a cell at the southeast of a $2\times2$ subarray, to prevent diagonal moves within path~$k$ from crossing. Finally, there's a secondary item \.{flag}, whose color is set to `\.*' if this solution is possibly not canonical under reflections. (It happens if the middle step of the first word is vertical.) @= for (k=1;k%c", encode(k-1),encode(l)); } printf(" flag\n"); @ @= { for (i=0;i; } @ @= for (i=0;i0:%c %c<%c:0\n", encode(k-1),encodeij(i,j),argv[k][0], encode(k-1),encodeij(i,j), encode(k-1),encodeij(i,j)); @ @= for (l=1;argv[k][l];l++) { flag=0; if (k==1) @; if (i) { if (j) @; @; if (j+1; } if (j) @; if (j+1; if (i+1; @; if (j+1; } } @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i,j-1),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i,j-1), encode(k-1),encodeij(i,j-1),encode(l)); @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i,j+1),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i,j+1), encode(k-1),encodeij(i,j+1),encode(l)); @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c%s\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i-1,j),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i-1,j), encode(k-1),encodeij(i-1,j),encode(l),flag?" flag:*":""); @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c%s\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i+1,j),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i+1,j), encode(k-1),encodeij(i+1,j),encode(l),flag?" flag:*":""); @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c %c/%c\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i-1,j-1),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i-1,j-1), encode(k-1),encodeij(i-1,j-1),encode(l), encode(k-1),encodeij(i,j)); @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c %c/%c\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i+1,j+1),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i+1,j+1), encode(k-1),encodeij(i+1,j+1),encode(l), encode(k-1),encodeij(i+1,j+1)); @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c %c/%c\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i+1,j-1),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i+1,j-1), encode(k-1),encodeij(i+1,j-1),encode(l), encode(k-1),encodeij(i+1,j)); @ @= printf("%c!%c %c:%c %c:%c %c>%c:%c %c<%c:%c %c>%c:%c %c<%c:%c %c/%c\n", encode(k-1),encode(l), encodeij(i,j),argv[k][l-1], encodeij(i-1,j+1),argv[k][l], encode(k-1),encode(l-1),encodeij(i,j), encode(k-1),encodeij(i,j),encode(l-1), encode(k-1),encode(l),encodeij(i-1,j+1), encode(k-1),encodeij(i-1,j+1),encode(l), encode(k-1),encodeij(i,j+1)); @ I assume here that |rows| is even and |cols| is odd. @= { for (ll=1;argv[k][ll];ll++) ; if (l==(ll>>1)) { if (i+i>=rows || j+j>=cols) continue; if (j+j==cols-1) flag=1; } } @*Index.