String permutation generator (Code Eval challenge)