private static int Permutate(char[] workingSet, int workingIndex, HashSet<String> seenAlready, HashSet<String> toMatch) {
        int result = 0;

        if (workingSet.length - 1 < workingIndex) {
            String permutation = new String(workingSet);
            if (!seenAlready.contains(permutation) && toMatch.contains(permutation)) {
                seenAlready.add(permutation);
                return 1;
            }
        } else {
            char head = workingSet[workingIndex];

            result += Permutate(workingSet, workingIndex + 1, seenAlready, toMatch);

            for (int i = workingIndex + 1; i < workingSet.length; i++) {
                char replacedHead = workingSet[i];
                if (head == replacedHead) {
                    continue;
                }

                workingSet[workingIndex] = replacedHead;
                workingSet[i] = head;
                result += Permutate(workingSet, workingIndex + 1, seenAlready, toMatch);
                workingSet[i] = replacedHead;
                workingSet[workingIndex] = head;
            }
        }
        return result;
    }