: invert ( perm -- perm' ) >alist sort-values keys ; : v-perm ( n -- perm ) [1,b] dup rest append but-last ; : full-perm ( seq n -- perm ) [ length dup ] [ v-perm ] bi* concat swap head ; : v-enc ( seq n -- seq' ) over [ full-perm invert ] dip nths >string ;