Initial (still buggy) version of string permutations algorithm