Пример #1
0
        private static bool BruteForce(string s)
        {
            foreach (char[] data in PalindromicPermutations.Permutations(s.ToCharArray(), 0))
            {
                if (PalindromicPermutations.IsPalindrome(data))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        private static IEnumerable <char[]> Permutations(char[] data, int index)
        {
            if (index >= data.Length - 1)
            {
                yield return(data);

                yield break;
            }

            for (int i = index; i < data.Length; i++)
            {
                ArrayUtilities.Swap(data, i, index);

                foreach (char[] permutation in PalindromicPermutations.Permutations(data, index + 1))
                {
                    yield return(permutation);
                }

                ArrayUtilities.Swap(data, i, index);
            }
        }