full permutation algorithm.