'Pollux key generator program Defint A-Z Dim Shared Perm[30], Num[30], Max, N Dim Shared Proxy$ Dim shared ncalls,depth,maxdepth 'Describe multiset: N=10 symbols 'four 0's, three 1's, three 2's Num[0] = 4 Num[1] = 3 Num[2] = 3 Max=2 N = Num[0] + Num[1] + Num[2] Proxy$ = ".-x" 'four dots GenPerms(N) 'generate 4200 keys Print "ncalls =";ncalls;" maxdepth=";maxdepth Input x$ Proxy$ = "-.x" 'four dashes GenPerms(N) 'generate 4200 keys Print "ncalls =";ncalls;" maxdepth=";maxdepth Input x$ Proxy$ = "x.-" 'four separator x's GenPerms(N) 'generate 4200 keys Print "ncalls =";ncalls;" maxdepth=";maxdepth Input x$ 'Convert permutation to symbols and 'print it. SUB PrintPerm For I=N-1 To 0 Step -1 Print Mid$(Proxy$,Perm[i]+1,1); Next I Print End Sub 'Recursive permutation generator 'for multisets. Sub GenPerms(n) depth=depth+1 if depth>maxdepth then maxdepth=depth ncalls=ncalls+1 If Num[0] = n Then PrintPerm Else For j=0 to Max If Num[j] > 0 Then Perm[n-1] = j Num[j] = Num[j]-1 GenPerms n-1 Num[j] = Num[j]+1 Perm[n-1] = 0 End If Next J End If depth=depth-1 End Sub