modified permutations_of_string algorithm