Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- namespace palindromeheheszki
- {
- class Program
- {
- static void Main(string[] args)
- {
- var stopwatch = new Stopwatch();
- stopwatch.Start();
- Random rnd = new Random();
- List<int> results = new List<int>();
- List<int> palindromes = new List<int>();
- for (var i = 100; i < 1000; i++)
- {
- for (var j = 100; j < 1000; j++)
- {
- int number = i * j;
- if (Check(number))
- {
- palindromes.Add(number);
- }
- }
- }
- stopwatch.Stop();
- System.Console.WriteLine($"Elapsed: {stopwatch.ElapsedMilliseconds}ms");
- Console.WriteLine(palindromes.Max());
- Console.ReadKey();
- bool Check(int x)
- {
- IEnumerable<char> s = x.ToString().ToCharArray();
- return s.SequenceEqual(s.Reverse());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment