Palindrome

Palindrome means that a word is the same spelled forwards and backwards. The strategy here is to find the middle of the word, fill the left buffer with the first half of the word, fill the right buffer with the second half of the word, reverse the character order in the right half and then compare the left half to the right half. If they are equal, then the word is a Palindrome.



using System;

public class Palindrome
{
    public static bool IsPalindrome(string word)
    {
        bool answer = true;
        int i=0;
        int len = count/2;
        int count = word.Length;
        char[] buffer;
        char[] l = new char[len];
        char[] r = new char[len];
        
        word = word.ToLower();
        buffer = word.ToCharArray();

        foreach(char c in buffer) // fill left buffer
        {
            l[i] = c;
                
            Console.WriteLine("l: " + l[i]);
                
            i++;
                
            if(i == count/2)
            {
               break; 
            }
        }
            
        Console.WriteLine();
            
        i = 0;
        Array.Reverse(buffer); // fill right buffer
        foreach(char c in buffer)
        {
            r[i] = c;
                
            Console.WriteLine("r: " + r[i]);
                
            i++;
                
            if(i == count/2)
            {
               break; 
            }
        }
        
        i = 0;
        foreach(char c in l) // now test left vs right
        {
            if(c != r[i])
            {
                answer = false;
            }
                
            i++;
        }

        return answer;
    }

    public static void Main(string[] args)
    {
        Console.WriteLine(Palindrome.IsPalindrome("Deleveled"));
    }
}