Created
May 1, 2013 13:48
-
-
Save jose-gomez/5495370 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
namespace PalindromeGist | |
{ | |
struct Program | |
{ | |
public static bool Espalindromo(string word) | |
{ | |
char[] origin = word.ToCharArray(); | |
for (int i = 0; i < word.Length; i++) | |
{ | |
if (origin[i] != origin[(origin.Length - 1) - i]) | |
{ | |
return false; | |
} | |
} | |
return true; | |
} | |
static void Main(string[] args) | |
{ | |
DateTime start = DateTime.Now; | |
// Realizar el trabajo | |
string sLine = ""; | |
using (TextReader reader = File.OpenText(@"C:\seed.txt")) | |
{ | |
sLine = reader.ReadToEnd(); | |
} | |
int counter = 0; | |
int lowRange = 0; | |
int highRange = 0; | |
string[] sLines = sLine.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries); | |
for (int i = 0; i < sLines.Length; i++ ) | |
{ | |
lowRange = int.Parse(sLines[i].Split(' ')[0].ToString()); | |
highRange = int.Parse(sLines[i].Split(' ')[1].ToString()); | |
for (int j = lowRange; j <= highRange; j++) | |
{ | |
if (Espalindromo(j.ToString())) | |
{ | |
counter++; | |
} | |
} | |
} | |
DateTime end = DateTime.Now; | |
double elapsedTime = end.Subtract(start).TotalSeconds; | |
Console.WriteLine("Total de Palindromos " + counter); | |
Console.WriteLine("Segundos Transcurridos " + elapsedTime); | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment