Exemplo n.º 1
0
    public void Largest_palindrome_from_triple_digit_factors()
    {
        var actual = Palindrome.Largest(100, 999);

        Assert.Equal(906609, actual.Value);
        Assert.Equal(new[] { Tuple.Create(913, 993) }, actual.Factors);
    }
Exemplo n.º 2
0
    public void Largest_palindrome_from_four_digit_factors()
    {
        var actual = Palindrome.Largest(1000, 9999);

        Assert.Equal(99000099, actual.Value);
        Assert.Equal(new[] { Tuple.Create(9901, 9999) }, actual.Factors);
    }
Exemplo n.º 3
0
        bool IsLychrel(BigInteger i, ref int iteration)
        {
            var temp        = i.ToString();
            var reverseLong = GetReverseLong(temp);
            var l           = i + reverseLong;
            var reverseL    = l.ToString();

            if (iteration > 50)
            {
                if (!PathCache.ContainsKey(i))
                {
                    PathCache.Add(i, iteration);
                }
                return(true);
            }

            if (Palindrome.IsPalindrome(reverseL))
            {
                if (!PathCache.ContainsKey(i))
                {
                    PathCache.Add(i, iteration);
                }
                return(false);
            }

            if (PathCache.ContainsKey(i))
            {
                iteration += PathCache[i];
                return(iteration >= 50);
            }

            iteration++;
            return(IsLychrel(l, ref iteration));
        }
Exemplo n.º 4
0
    public void Largest_palindrome_from_double_digit_actors()
    {
        var actual = Palindrome.Largest(10, 99);

        Assert.Equal(9009, actual.Value);
        Assert.Equal(new[] { Tuple.Create(91, 99) }, actual.Factors);
    }
Exemplo n.º 5
0
 public void LinqIsPalindromeReturnsTrueForPalindrome()
 {
     foreach (var word in palindromes)
     {
         Assert.IsTrue(Palindrome.LinqIsPalindrome(word));
     }
 }
        static void Main(string[] args)
        {
            Palindrome Palindrome = new Palindrome("never Odd, or Even.");

            Console.WriteLine(Palindrome.isPalindrome());
            Console.ReadKey();
        }
Exemplo n.º 7
0
        public void GetPhrase_GetPhrase_String()
        {
            string     phrase        = "this is a phrase";
            Palindrome newPalindrome = new Palindrome(phrase, false);

            Assert.AreEqual(phrase, newPalindrome.GetPhrase());
        }
Exemplo n.º 8
0
    public void Smallest_palindrome_from_four_digit_factors()
    {
        var actual = Palindrome.Smallest(1000, 9999);

        Assert.That(actual.Value, Is.EqualTo(1002001));
        Assert.That(actual.Factors, Is.EqualTo(new[] { Tuple.Create(1001, 1001) }));
    }
        public IActionResult Index(Palindrome input)
        {
            if (input.Inputword == null)
            {
                input.Message = "Result";
                return(View(input));
            }
            else
            {
                string inputWord = input.Inputword.ToLower();
                inputWord = inputWord.Replace(" ", "");
                string revWord;
                char[] charArray = inputWord.ToCharArray();
                Array.Reverse(charArray);
                revWord = new string(charArray);

                if (revWord == inputWord)
                {
                    input.Isclear      = true;
                    input.IsPalindrome = true;
                    input.Message      = $"Success {input.Inputword} is a Palindrome!";
                }
                else
                {
                    input.Isclear = true;
                    input.Message = $"Sorry {input.Inputword} is NOT a Palindrome!";
                }

                return(View(input));
            }
        }
Exemplo n.º 10
0
        public void PalindromeConstructor_CreatesInstanceOfPalindrome_Palindrome()
        {
            string     phrase        = "";
            Palindrome newPalindrome = new Palindrome(phrase, false);

            Assert.AreEqual(typeof(Palindrome), newPalindrome.GetType());
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            Palindrome pal = new Palindrome();
            String     val = Console.ReadLine();

            pal.palindrome(val);
        }
Exemplo n.º 12
0
        public void SampleTest()
        {
            var s      = File.ReadAllText(@"f:\Pactice\test.txt");
            var result = Palindrome.palindromeIndex("hgygsvlfcwnswtuhmyaljkqlqjjqlqkjlaymhutwsnwcwflvsgygh");

            Assert.AreEqual(44, result);
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            Console.WriteLine("----------------------START ALGORITHM TESTS----------------------");

            SelectionSort.RunTests();
            InsertionSort.RunTests();
            Factorial.RunTests();
            Palindrome.RunTests();
            Recursion.RunTests();
            MergeSort.RunTests();
            QuickSort.RunTests();
            BreadthFirstSearch.RunTests();

            Console.WriteLine("----------------------END ALGORITHM TESTS----------------------");
            Console.WriteLine("----------------------START PATTERN TESTS----------------------");

            BFS.RunTests();
            DFS.RunTests();
            SlidingWindow.RunTests();
            TwoPointers.RunTests();

            FastSlowPointers.RunTests();
            MergeIntervals.RunTests();

            Console.WriteLine("----------------------END PATTERN TESTS----------------------");
        }
Exemplo n.º 14
0
        public long Largest(long maxFactor)
        {
            long largestpalindromeFound = -1;

            for (long i1 = maxFactor - 1; i1 > 0; i1--)
            {
                if (i1 * i1 < largestpalindromeFound)
                {
                    break;
                }

                for (long i2 = i1; i2 > 0; i2--)
                {
                    long currentProduct = i1 * i2;
                    if (currentProduct > largestpalindromeFound)
                    {
                        if (Palindrome.IsPalindrome(currentProduct))
                        {
                            largestpalindromeFound = currentProduct;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(largestpalindromeFound);
        }
Exemplo n.º 15
0
        public void Palindrome_WhenReverse_ReturnReverse()
        {
            string input  = "Palindrome";
            string output = Palindrome.Reverse(input);

            Assert.AreEqual("emordnilaP", output);
        }
Exemplo n.º 16
0
    public void Largest_palindrome_from_four_digit_factors()
    {
        var actual = Palindrome.Largest(1000, 9999);

        Assert.That(actual.Value, Is.EqualTo(99000099));
        Assert.That(actual.Factors, Is.EqualTo(new[] { Tuple.Create(9901, 9999) }));
    }
Exemplo n.º 17
0
        public void Palindrome_WhenChecked_ReturnInvalid()
        {
            string input  = "Palindrome";
            string output = Palindrome.IsPalindrome(input);

            Assert.AreEqual($"The word {input} is not a Palindrome", output);
        }
Exemplo n.º 18
0
        public void IsThisAPalindrome(string word, bool expected)
        {
            var palindromeInstance = new Palindrome();
            var actual             = palindromeInstance.IsThisAPalindrome(word);

            Assert.Equal(expected, actual);
        }
Exemplo n.º 19
0
        public void Palindrome_WhenDifCase_ReturnValid()
        {
            string input  = "Level";
            string output = Palindrome.IsPalindrome(input);

            Assert.AreEqual($"The word {input} is a Palindrome", output);
        }
Exemplo n.º 20
0
 public void LinqIsPalindromeReturnsFalseForNormalWords()
 {
     foreach (var word in words)
     {
         Assert.IsFalse(Palindrome.LinqIsPalindrome(word));
     }
 }
Exemplo n.º 21
0
        public void Palindrome_WhenReverse_ReturnString()
        {
            string input  = "Palindrome";
            string output = Palindrome.Reverse(input);

            Assert.IsInstanceOf(typeof(string), output);
        }
Exemplo n.º 22
0
 public void TestMethod2()
 {
     Assert.IsFalse(Palindrome.IsPalindrome("Boo Hoo"));
     Assert.IsFalse(Palindrome.IsPalindrome("This is a test"));
     Assert.IsFalse(Palindrome.IsPalindrome("Racefar"));
     Assert.IsFalse(Palindrome.IsPalindrome("Racca"));
 }
Exemplo n.º 23
0
        public string Run()
        {
            long ans = 0;

            for (long i = 1; i < TEN_THOUSAND; i++)
            {
                bool       isLychel = true;
                BigInteger b        = new BigInteger(i);
                for (int j = 0; j < 50; j++)
                {
                    b = b + BigInteger.Parse(new string(b.ToString().Reverse().ToArray()));
                    if (Palindrome <char> .IsPalindrome(b.ToString().ToList()))
                    {
                        isLychel = false;
                        break;
                    }
                }
                if (isLychel)
                {
                    ans++;
                }
            }

            return(ans.ToString());
        }
Exemplo n.º 24
0
        public void Palindrome_False(string str)
        {
            var p      = new Palindrome();
            var result = p.Palindrome1(str);

            Assert.IsFalse(result);
        }
Exemplo n.º 25
0
    public void Smallest_palindrome_from_single_digit_factors()
    {
        var actual = Palindrome.Smallest(9);

        Assert.That(actual.Value, Is.EqualTo(1));
        Assert.That(actual.Factors, Is.EqualTo(new[] { Tuple.Create(1, 1) }));
    }
Exemplo n.º 26
0
    public void Smallest_palindrome_from_double_digit_factors()
    {
        var actual = Palindrome.Smallest(10, 99);

        Assert.Equal(121, actual.Value);
        Assert.Equal(new[] { Tuple.Create(11, 11) }, actual.Factors);
    }
Exemplo n.º 27
0
    public void Largest_palindrome_from_triple_digit_factors()
    {
        var actual = Palindrome.Largest(100, 999);

        Assert.That(actual.Value, Is.EqualTo(906609));
        Assert.That(actual.Factors, Is.EqualTo(new[] { Tuple.Create(913, 993) }));
    }
Exemplo n.º 28
0
    public void Largest_palindrome_from_single_digit_factors()
    {
        var actual = Palindrome.Largest(9);

        Assert.Equal(9, actual.Value);
        Assert.Equal(new [] { Tuple.Create(1, 9), Tuple.Create(3, 3) }, actual.Factors);
    }
Exemplo n.º 29
0
    public void Largest_palindrome_from_single_digit_factors()
    {
        var actual = Palindrome.Largest(9);

        Assert.That(actual.Value, Is.EqualTo(9));
        Assert.That(actual.Factors, Is.EqualTo(new [] { Tuple.Create(1, 9), Tuple.Create(3, 3) }));
    }
Exemplo n.º 30
0
    public void Smallest_palindrome_from_four_digit_factors()
    {
        var actual = Palindrome.Smallest(1000, 9999);

        Assert.Equal(1002001, actual.Value);
        Assert.Equal(new[] { Tuple.Create(1001, 1001) }, actual.Factors);
    }
Exemplo n.º 31
0
 public static void PalindromeMain()
 {
     System.Console.Write("please enter a palindrome: ");
     string palindrome = System.Console.ReadLine();
     Palindrome instance = new Palindrome();
     if (instance.IsPalindrome(palindrome))
     {
         System.Console.WriteLine("\"{0}\" is a palindrome.", palindrome);
     }
     else
     {
         System.Console.WriteLine("\"{0}\" is NOT a palindrome.", palindrome);
     }
 }