word permutation problem