my initial solution to this problem, using a recursive permutation function