#VM (VowelMinded.txt) to create and solve Vowel-Minded puzzles read `VMP.txt`: read milim: ez:=proc(): print(`Gr(n,DB, K), Gr(3,Anglit, {[1,a],[2,a]}); VT1(W,SET,X); FindMates(W,DB,SET), FindMates([p,o,o,r,l,y],Anglit, {a,e,i,o,u}); `): print(`Ptor(6,Anglit,{[1,f],[2,l],[5,n],[6,t]}, {a,e,i,o,u});`): print(`FindPairs(Anglit,{a,e,i,o,u},1000);`): print(`Sug(P,SET);`): print(`Arrange(KHIN,{a,e,i,o,u}): `): print(`PRINTPUZ(PUZ,X,N); `): print(`PRINTSOL(PUZ,N)`): print(`MakeBook(KHIN,{a,e,i,o,u},5,2,2); `): end: Gr:=proc(n,DB,L) local mu,i,j: mu:={}: for i from 1 to nops(DB) do if nops(DB[i])=n and {seq(evalb(DB[i][L[j][1]]=L[j][2]),j=1..nops(L))}={true} then mu:=mu union {DB[i]}: fi: od: mu: end: #VT1(W,SET,X): inputs a word W in an alphabet, and a set SET of letter X NOT in that alphabet #outputs the same word where all the members of SET are replaced by X. Try #VT1([d,o,r,o,n],{a,e,o,u,y}); VT1:=proc(W,SET, X) local s: subs({seq(s=X,s in SET)},W): end: #FindMates(W,DB,SET): Inputs a word W, a data-base (list of lists) DB and a set of letters, SET #outputs all the words such that if you delete the letters of W that belong to SET, #the deleted letters also belong to SET. Try #FindMates([p,o,o,r,l,y],Anglit, {a,e,i,o,u}); FindMates:=proc(W,DB,SET) local I1,GU,MU,KU,J1,LU: if not member(W,{op(DB)}) then print(W, `is not a word in our vocabulary list`): RETURN(FAIL): fi: GU:={}: KU:=[]: for I1 from 1 to nops(W) do if not member(W[I1],SET) then GU:={op(GU),[I1,W[I1]]}: else KU:=[op(KU),I1]: fi: od: MU:=Gr(nops(W),DB,GU): LU:={}: for I1 from 1 to nops(MU) do if {seq(MU[I1][KU[J1]],J1=1..nops(KU))} minus SET={} then LU:=LU union {MU[I1]}: fi: od: MU:={}: for I1 from 1 to nops(LU) do if {seq(evalb(LU[I1][KU[J1]]=W[KU[J1]]),J1=1..nops(KU))}={false} then MU:=MU union {LU[I1]}: fi: od: MU: end: #Ptor(n,DB,L,SET): #Ptor(6,Anglit,{[1,f],[2,l],[5,n],[6,t]},{a,e,i,o,u}); Ptor:=proc(n,DB,L,SET) local GU,I1,K1,MU,KA: GU:=Gr(n,DB,L): MU:={}: for I1 from 1 to nops(GU) do KA:=FindMates(GU[I1],DB,SET): MU:=MU union {seq({GU[I1],KA[K1]}, K1=1..nops(KA)) }: od: MU: end: #FindPairs(Anglit,{a,e,i,o,u},1000); FindPairs:=proc(DB,SET,K) local I1,GU: GU:={}: for I1 from 1 to min(nops(DB),K) do if FindMates(DB[I1],DB,SET)<>{} then GU:=GU union {DB[I1]}: fi: od: GU: end: #Sug(P,SET): given a puzzle with a set SET, finds the type [NumberOfLetters, NumberOfVowels,NumberOfSolutions]. Try: #Sug(KHIN[100],{a,e,i,o,u}); Sug:=proc(P,SET) local P1,KA,I1: P1:=P[2]: KA:=0: for I1 from 1 to nops(P1[1]) do if member(P1[1][I1],SET) then KA:=KA+1: fi: od: [nops(P1[1]), KA, nops(P1)]: end: #Arrange(KHIN,{a,e,i,o,u}): #arranges the list of puzzles into types Arrange:=proc(DB,SET) local GU,I1,T1,GU1: option remember: GU:={seq(Sug(DB[I1],SET),I1=1..nops(DB))}: GU: for GU1 in GU do T1[GU1]:=[]: od: for I1 from 1 to nops(DB) do T1[Sug(DB[I1],SET)]:=[op(T1[Sug(DB[I1],SET)]), DB[I1]]: od: GU, op(T1): end: PRINTPUZ:=proc(PUZ,X,N) local KA,P: KA:=nops(PUZ[2]): P:=PUZ[1]: P:=subs(X=___,P): if KA=2 then print(cat(N, ` . ` , op(subs(X=___,P)) , ` `, op(subs(X=___,P)) ) ): elif KA=3 then print(cat(N, ` . ` , op(subs(X=___,P)) , ` `, op(subs(X=___,P)), ` `, op(subs(X=___,P)) ) ): elif KA=4 then print(cat(N, ` . ` , op(subs(X=___,P)) , ` `, op(subs(X=___,P)), ` `, op(subs(X=___,P)), ` `, op(subs(X=___,P)) ) ): else RETURN(FAIL): fi: end: #PRINTSOL(PUZ,N) PRINTSOL:=proc(PUZ,N) local KA,P: KA:=nops(PUZ[2]): P:=PUZ[2]: if KA=2 then print(cat(N, ` . ` , op(P[1]) , ` `, op(P[2]) ) ): elif KA=3 then print(cat(N, ` . ` , op(P[1]) , ` `, op(P[2]), ` `, op(P[3]) ) ): elif KA=4 then print(cat(N, ` . ` , op(P[2]) , ` `, op(P[2]), ` `, op(P[3]) ,` `, op(P[3]) ) ): else RETURN(FAIL): fi: end: #MakeBook(DB,SET,N1,N2,N3): A puzzle book with N1 letters N2 vowels and N3 solutions. Try: #MakeBook(KHIN,{a,e,i,o,u},5,2,2) MakeBook:=proc(DB,SET,N1,N2,N3) local GU,N: GU:=Arrange(DB,SET): if not member([N1,N2,N3],GU[1]) then RETURN(FAIL): fi: GU:=GU[2][[N1,N2,N3]]: print(nops(GU), `Vowel-Minded Puzzles with`, N1, `letters `, N2, `vowels and `, N3, `solutions each`): print(``): print(`By Shalosh B. Ekhad `): print(``): print(`In the clues below the vowels, a,e,i,o,u, are replaced by blanks. find the`, N3, `words that match `): for N from 1 to nops(GU) do print(``): PRINTPUZ(GU[N],X,N): print(``): od: print(`-----------------------------------------------------------`): print(``): print(``): print(``): print(``): print(``): print(``): print(`Solutions to the above puzzles`): for N from 1 to nops(GU) do print(``): PRINTSOL(GU[N],N): print(``): od: end: