Implementation in Python of backtracking permutation solution.