Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace EulerPalindrome {
- class Program {
- static void Main(string[] args) {
- string test2 = "Anna";
- Console.WriteLine(test2.RightIndex(1));
- Console.WriteLine(test2.IsPalindrome());
- }
- }
- static class Extensions
- {
- public static bool IsPalindrome(this string input)
- {
- input = input.ToLower();
- int numberOfComparisons = input.Length/2;
- numberOfComparisons.Dump();
- if (numberOfComparisons < 1)
- return false;
- bool retVal = true;
- for (int numCompare = 1; numCompare <= numberOfComparisons; numCompare++)
- {
- input.LeftIndex(numCompare).Dump();
- input.RightIndex(numCompare).Dump();
- if (input.LeftIndex(numCompare) != input.RightIndex(numCompare))
- retVal = false;
- }
- return retVal;
- }
- public static string LeftIndex(this string input, int numIndex)
- {
- return input.Substring(numIndex, 1);
- }
- public static string RightIndex(this string input, int numIndex)
- {
- return input.Substring(input.Length - numIndex, 1);
- }
- }
- }
Add Comment
Please, Sign In to add comment