Guest User

Untitled

a guest
Jun 1st, 2018
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5.  
  6. namespace palindromeheheszki
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var stopwatch = new Stopwatch();
  13.             stopwatch.Start();
  14.             Random rnd = new Random();
  15.             List<int> results = new List<int>();
  16.             List<int> palindromes = new List<int>();
  17.  
  18.             for (var i = 100; i < 1000; i++)
  19.             {
  20.                 for (var j = 100; j < 1000; j++)
  21.                 {
  22.                     int number = i * j;
  23.                     if (Check(number))
  24.                     {
  25.                         palindromes.Add(number);
  26.                     }
  27.                 }
  28.             }
  29.             stopwatch.Stop();
  30.             System.Console.WriteLine($"Elapsed: {stopwatch.ElapsedMilliseconds}ms");
  31.             Console.WriteLine(palindromes.Max());
  32.             Console.ReadKey();
  33.  
  34.             bool Check(int x)
  35.             {
  36.                 IEnumerable<char> s = x.ToString().ToCharArray();
  37.                 return s.SequenceEqual(s.Reverse());
  38.             }
  39.         }        
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment