read KING: #Have KING in the same directory #In Window replace by this line: read `C:\\KING.txt`: Help1:=proc(): print(`LCS(w1,w2)`): end: #LCS(w1,w2): Given two lists in any alphabet #finds the longest common subsequence LCS:=proc(w1,w2) local L1,L2,L3,a,b,i,j,tem,m,w,Di,walk1: a:=nops(w1): b:=nops(w2): m:=max(a,b): L1:=[[0$(m+1)]$(m+1)]: L2:=[[0$(m+1)]$(m+1)]: for i from 1 to a do for j from 1 to b do if w1[i]=w2[j] then L3[i][j]:=1: else L3[i][j]:=-1: fi: od: od: tem:=BP1(L1,L2,L3,a,b): walk1:=tem[1]: Di:=[]: for i from 1 to nops(walk1)-1 do if walk1[i+1][1]=walk1[i][1]+1 and walk1[i+1][2]=walk1[i][2]+1 then Di:=[op(Di) , w1[walk1[i][1]+1]]: fi: od: Di,tem[2]: end: