Skip to content

Instantly share code, notes, and snippets.

@hminaya
Created April 22, 2013 22:52
Show Gist options
  • Save hminaya/5439286 to your computer and use it in GitHub Desktop.
Save hminaya/5439286 to your computer and use it in GitHub Desktop.
Ejemplo en C# (para correr con mono) de como sacar un palindromo
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
namespace palindrome
{
class MainClass
{
public static void Main (string[] args)
{
var reloj = new Stopwatch();
reloj.Start();
var cantidadPalindromos = 0;
var archivo = File.ReadAllLines("seed.txt");
Console.WriteLine("Archivo cargado en memoria {0}", reloj.Elapsed);
//Lectura del archivo
foreach (var linea in archivo)
{
int num1 = Convert.ToInt32(linea.Split(' ')[0]);
int num2 = Convert.ToInt32(linea.Split(' ')[1]);
for (int i = num1; i < num2; i++) {
String b = i.ToString();
if (b.SequenceEqual(b.Reverse())) {
cantidadPalindromos++;
}
}
}
reloj.Stop();
Console.WriteLine("{0} palíndromos encontrados. {1}", cantidadPalindromos, reloj.Elapsed);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment