> restart: with(plots): with(plottools): with(StringTools, UpperCase): #Crossword Problem 7 # Initially only the letters on the white squares are given. cwm[1,1]:="s":cwm[1,2]:="*":cwm[1,3]:="o":cwm[1,4]:="*":cwm[1,5]:="f": cwm[2,1]:="*":cwm[2,2]:="a":cwm[2,3]:="*":cwm[2,4]:="e":cwm[2,5]:="*": cwm[3,1]:="a":cwm[3,2]:="*":cwm[3,3]:="e":cwm[3,4]:="*":cwm[3,5]:="a": cwm[4,1]:="*":cwm[4,2]:="a":cwm[4,3]:="*":cwm[4,4]:="d":cwm[4,5]:="*": cwm[5,1]:="s":cwm[5,2]:="*":cwm[5,3]:="a":cwm[5,4]:="*":cwm[5,5]:="h": #Drawing the crossword grid no_side_square :=5: no_side_squareV:=5: x_sw:=0:y_sw:=0: #Dimensions of each small rectangle width:=1:depth:=1: #Calcs for rectangular grid for i from 1 to no_side_square do for j from 1 to no_side_squareV do if (i mod 2=0) and (j mod 2=0) then c[i,j] := rectangle([x_sw+(i-1)*width,y_sw+(j-1)*depth], [x_sw+i*width,y_sw+j*depth],color=white): elif (i mod 2=0) or (j mod 2=0) then c[i,j] := rectangle([x_sw+(i-1)*width,y_sw+(j-1)*depth], [x_sw+i*width,y_sw+j*depth],color=wheat): else c[i,j] := rectangle([x_sw+(i-1)*width,y_sw+(j-1)*depth], [x_sw+i*width,y_sw+j*depth],color=white): end if od: od: #Next line draws the rectangular pattern - grid only #plots[display](seq(seq(c[i,j], i=1..no_side_square), j=1..no_side_squareV), scaling=constrained, axes=NONE); #Problem 7 cwm[] used tx:=textplot( [seq( seq([j-.5,5.5-i,UpperCase(cwm[i,j])],i=1..5), j=1..5) ]): plots[display](tx,seq(seq(c[i,j], i=1..no_side_square), j=1..no_side_squareV), scaling=constrained, axes=NONE); # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Aim is to find words in the dictionary for all 10 words. The above cwm[,] - cross-word matrix - # are the letters which are given. #Program puts all possible words in separate files named Dict_ac1, Dict_dn1... etc #Across words - NB this section is unused as the cwm[,] are unknown wa[1]:=cat(cwm[1,1],cwm[1,2],cwm[1,3],cwm[1,4],cwm[1,5]): wa[2]:=cat(cwm[2,1],cwm[2,2],cwm[2,3],cwm[2,4],cwm[2,5]): wa[3]:=cat(cwm[3,1],cwm[3,2],cwm[3,3],cwm[3,4],cwm[3,5]): wa[4]:=cat(cwm[4,1],cwm[4,2],cwm[4,3],cwm[4,4],cwm[4,5]): wa[5]:=cat(cwm[5,1],cwm[5,2],cwm[5,3],cwm[5,4],cwm[5,5]): #Down words - NB this section is unused as the cwm[,] are unknown wd[1]:=cat(cwm[1,1],cwm[2,1],cwm[3,1],cwm[4,1],cwm[5,1]): wd[2]:=cat(cwm[1,2],cwm[2,2],cwm[3,2],cwm[4,2],cwm[5,2]): wd[3]:=cat(cwm[1,3],cwm[2,3],cwm[3,3],cwm[4,3],cwm[5,3]): wd[4]:=cat(cwm[1,4],cwm[2,4],cwm[3,4],cwm[4,4],cwm[5,4]): wd[5]:=cat(cwm[1,5],cwm[2,5],cwm[3,5],cwm[4,5],cwm[5,5]): # Below are lists of possible words which fit the puzzle. acL[1] is shorthand for # across clue List 1. Similarly dnL[2] stands for the list of possible words for # 2 Down acL[1]:=["scoff", "skoff", "snoff"]: acL[2]:=["hazel", "hamel", "camel", "capel", "lamel", "lapel", "tazel"]: acL[3]:=["arena", "avena"]: acL[4]:=["yards", "pands", "pards", "eards", "kands", "gards", "nards", "lands", "lards", "bards", "bands", "hands", "wands", "wards", "hards", "rands", "mands"]: acL[5]:=["stash", "snash", "slash", "smash"]: dnL[1]:=["scabs", "scags", "scams", "scans", "scars", "shabs", "shags", "shahs", "shams", "shans", "shaps", "shaws", "shays", "scaws", "slabs", "slaes", "slags", "slams", "slaps", "slaws", "slays", "stabs", "stags", "staps", "stars", "stays", "staws"]: dnL[2]:=["param", "pavan", "karat", "naval", "caman", "carac", "caval", "carat"]: dnL[3]:=["opera", "ozena"]: dnL[4]:=["fends"]: dnL[5]:=["flash"]: for l from 1 to 5 do # letter in Across list for m from 1 to 5 do # letter in Down list for i from 1 to nops(acL[l]) do # choosing word in across list for k from 1 to nops(dnL[m]) do # choosing word in down list for kA from 1 to 5 do # going along each letter of Ac word for kD from 1 to 5 do # going along each letter of Dn word #printf below is for investigative debugging purposes only #printf("l=%d m=%d i=%d k=%d kA=%d kD=%d\n",l,m,i,k,kA,kD); # 2nd letter of word in acL[4] = 4th letter of word in dnL[2] # acL[4][k][2] = 4th letter of word in dnL[2][i][4] # ie acL[4][k][2] = dnL[2][i][4] # ith letter in acL[j][k][i] = jth letter in dnL[i] dnL[i][i][j] # lth letter in acL[l][k][l] = mth letter in dnL[m] dnL[i][i][m] # # # # # # # # # # # # # # # # Error, invalid subscript selector # Reason for failing: # Failing owing to k=26 for list dnL[1] - but dnL[2] - (and others) - has fewer words # # # # # # # # # # # # # # # if acL[l][i][1] = dnL[1][k][kD] and acL[l][i][2] = dnL[2][k][kD] and acL[l][i][3] = dnL[3][k][kD] and acL[l][i][4] = dnL[4][k][kD] and acL[l][i][5] = dnL[5][k][kD] then printf("l=%d i=%d acL[%d][%d]=%s acL[%d][%d][%d]=%s dnL[%d][%d][%d]=%s dnL[%d][%d]=%s\n" ,l,i,l,i,acL[l][i] ,l,i,kA,acL[l][i][kA], m,k,kD, dnL[m][k][kD],m,k,dnL[m][k]); end if: end do: #kD #printf("kA=%d\n\n",kA); end do; # was j - kA printf("k=%d\n\n",k); end do; #k #printf("i=%d\n\n",i); end do; #i #printf("m=%d\n\n",m); end do; #m #printf("l=%d\n\n",l); end do; #l