Mistři v programování na #hovnokod

C# #1605

Když dojde inspirace, nastupuje hrubá síla. :)

static void Main(string[] args)
{
	Console.WriteLine("Výsledkem budou všechna pěticiferná čísla, která mají daný ciferný součet a právě tři různé cifry.");
	Console.WriteLine("Zadejte hodnotu ciferného součtu:");
	byte a = Convert.ToByte(Console.ReadLine());
	Console.WriteLine();
	if (a > 42 || a < 3) { Console.WriteLine("Tato operace nelze provést. Program se ukončí."); Console.ReadLine(); }
	else
	{
		int n = 0;
		byte p1=1, p2=0, p3=0, p4=0, p5=2;
		int pom;
		do
		{
			pom = a;
			pom = pom - p1 - p2 - p3 - p4 - p5;
			if (pom == 0)
			{
				if ((p1 == p2 && p2 == p3 && p4 != p3 && p5 != p3 && p4 != p5)
					|| (p2 == p3 && p3 == p4 && p2 != p1 && p2 != p5 && p1 != p5)
					|| (p3 == p4 && p4 == p5 && p1 != p3 && p2 != p3 && p1 != p2)
					|| (p1 == p2 && p2 == p4 && p3 != p1 && p5 != p4 && p3 != p5)
					|| (p1 == p2 && p2 == p5 && p3 != p5 && p3 != p1 && p5 != p1)
					|| (p2==p3&&p3==p5&&p1!=p2&&p4!=p2&&p4!=p1)
					|| (p2==p4&&p4==p5&&p1!=p2&&p3!=p2&&p1!=p3)
					|| (p1==p3&&p3==p4&&p2!=p1&&p5!=p1&&p2!=p5)
					|| (p1==p4&&p4==p5&&p2!=p1&&p3!=p1&&p2!=p3)
					|| (p1==p3&&p3==p5&&p2!=p1&&p4!=p1&&p2!=p4)
					|| (p1==p2&&p2!=p3&&p3==p4&&p5!=p3&&p5!=p1)//
					|| (p1==p2&&p3==p5&&p1!=p3&&p4!=p1&&p4!=p3)
					|| (p1==p2&&p4==p5&&p1!=p4&&p3!=p1&&p3!=p4)
					|| (p2==p3&&p4==p5&&p2!=p4&&p1!=p2&&p1!=p4)
					|| (p2==p3&&p1==p4&&p1!=p2&&p5!=p4&&p5!=p3)
					|| (p2==p3&&p1==p5&&p1!=p2&&p4!=p5&&p4!=p1)
					|| (p1==p3&&p2==p4&&p1!=p2&&p5!=p1&&p5!=p2)
					|| (p1==p3&&p2==p5&&p1!=p2&&p4!=p1&&p4!=p2)
					|| (p1==p3&&p4==p5&&p4!=p1&&p2!=p1&&p2!=p5)
					|| (p1==p4&&p2==p3&&p1!=p2&&p5!=p4&&p5!=p3)
					|| (p1==p4&&p2==p5&&p1!=p2&&p3!=p2&&p3!=p4)
					|| (p1==p4&&p3==p5&&p1!=p3&&p2!=p1&&p2!=p3)
					|| (p1==p5&&p2==p3&&p1!=p2&&p4!=p1&&p4!=p3)
					|| (p1==p5&&p2==p4&&p1!=p2&&p3!=p1&&p3!=p2)
					|| (p1==p5&&p3==p5&&p3!=p1&&p2!=p1&&p2!=p3)
					
				)
				{ Console.Write(p1); Console.Write(p2); Console.Write(p3); Console.Write(p4); Console.WriteLine(p5); n++; }
			}
			p5++;
			if (p5 == 10) { p5 = 0; p4++; }
			if (p4 == 10) { p4 = 0; p3++; }
			if (p3 == 10) { p3 = 0; p2++; }
			if (p2 == 10) { p2 = 0; p1++; }

		} while (p1 < 10);
		Console.WriteLine();
		Console.WriteLine("Celkem: " + n + " čísel");
	} Console.ReadLine();


}

Pavel Valach,