added iterative permutation

need to do condition checking