library(gtools) n=8 k=5 a=permutations(n,n) b=permutations(n,k) seged=function(aa,bb){ prod((which(aa==bb[c(1:(length(bb)-1))])