Trying to wrap my head around generating permutations