Created
January 18, 2011 20:04
-
-
Save henrik-ch/785037 to your computer and use it in GitHub Desktop.
for Euler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment