Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Nikola-Andreev/1d9ecebec64b909b71a81224bd411eb4 to your computer and use it in GitHub Desktop.
Save Nikola-Andreev/1d9ecebec64b909b71a81224bd411eb4 to your computer and use it in GitHub Desktop.
25.Master Numbers
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Globalization;
using System.Text.RegularExpressions;
namespace Praktice
{
class Program
{
static void Main(string[] args)
{
int a = int.Parse(Console.ReadLine());
List<int> symetric = FindSymetrics(a);
List<int> divisible = DivisbleBy7(symetric);
List<int> master = HoldEvenDigith(divisible);
foreach (var item in master)
{
Console.WriteLine(item);
}
}
private static List<int> HoldEvenDigith(List<int> divisible)
{
List<int> result = new List<int>();
foreach (var item in divisible)
{
string a = item.ToString();
for (int i = 0; i < a.Length; i++)
{
char b = a[i];
int c = int.Parse(b.ToString());
if (c % 2 == 0)
{
if (!result.Contains(item))
{
result.Add(item);
}
}
}
}
return result;
}
private static List<int> DivisbleBy7(List<int> symetric)
{
List<int> result = new List<int>();
foreach (var num in symetric)
{
int sum = 0;
int b = num;
while (b > 0)
{
int a = b % 10;
b = b / 10;
sum += a;
}
if (sum%7==0)
{
result.Add(num);
}
}
return result;
}
private static List<int> FindSymetrics(int a)
{
List<int> result = new List<int>();
for (int i = 0; i < a; i++)
{
int num = i;
int reverse = 0;
while (num > 0)
{
int remainder = num % 10;
reverse = reverse * 10 + remainder;
num /= 10;
if (i == reverse)
{
result.Add(i);
}
}
}
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment