stefan1919

Stuck Numbers

Sep 16th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication6
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             string[] input = Console.ReadLine().Split(' ');
  15.             List<List<string>> subsetGood = new List<List<string>>();
  16.             double combinations = Math.Pow(2, n);
  17.             for (int i = 0; i < combinations; i++)
  18.             {
  19.                 int counter = 0;
  20.                 List<string> subset = new List<string>();
  21.                 for (int bitPosition = 0; bitPosition < n; bitPosition++)
  22.                 {
  23.                    
  24.                     if ((i & (1 << bitPosition)) != 0)
  25.                     {
  26.                         subset.Add(input[bitPosition]);
  27.                         counter++;
  28.                     } // if bitPosition
  29.                 }// bitwise for
  30.                 if (counter == 4)
  31.                 {
  32.                     subsetGood.Add(subset);
  33.                 }
  34.             }// for with combinations
  35.             foreach (var list in subsetGood)
  36.             {
  37.                 List<List<string>> subsetTwoElementsGood = new List<List<string>>();
  38.                 double newCombinations = Math.Pow(2, 4);
  39.             for (int i = 0; i < newCombinations; i++)
  40.             {
  41.                 List<string> subset = new List<string>();
  42.                 int counter = 0;
  43.                 for (int bitPosition = 0; bitPosition < 4; bitPosition++)
  44.                 {
  45.                     if ((i & (1 << bitPosition)) != 0)
  46.                     {
  47.                         subset.Add(list[bitPosition]);
  48.                         counter++;
  49.                     }
  50.                 }// for bitPosition2
  51.                 if (counter == 2)
  52.                 {
  53.                     subsetTwoElementsGood.Add(subset);
  54.                 }// if counter = 2
  55.             }// for new Combinations
  56.            
  57.                 for (int p = 0; p < subsetTwoElementsGood.Count; p++)
  58.                 {
  59.                     List<string> subset = new List<string>();
  60.                     int checkFirstTwo = 0;
  61.                     int checkSecondTwo = 0;
  62.                     for (int check = 0; check < subsetTwoElementsGood.Count; check++)
  63.                     {
  64.                         if (check == p)
  65.                         {
  66.                             continue;
  67.                         }
  68.                        
  69.                         else
  70.                         {
  71.                             checkFirstTwo = int.Parse(subsetTwoElementsGood[p][0] + subsetTwoElementsGood[p][1]);
  72.                             checkSecondTwo = int.Parse(subsetTwoElementsGood[check][0] + subsetTwoElementsGood[check][1]);
  73.                             if ((checkFirstTwo == checkSecondTwo) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][1]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][1]))
  74.                             {
  75.                                 Console.WriteLine("{0}|{1}={2}|{3}", subsetTwoElementsGood[p][0], subsetTwoElementsGood[p][1], subsetTwoElementsGood[check][0], subsetTwoElementsGood[check][1]);
  76.                             }
  77.                             else
  78.                             {
  79.                                 checkFirstTwo = int.Parse(subsetTwoElementsGood[p][1] + subsetTwoElementsGood[p][0]);
  80.                                 checkSecondTwo = int.Parse(subsetTwoElementsGood[check][0] + subsetTwoElementsGood[check][1]);
  81.                                 if ((checkFirstTwo == checkSecondTwo) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][1]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][1]))
  82.                                 {
  83.                                     Console.WriteLine("{0}|{1}={2}|{3}", subsetTwoElementsGood[p][1], subsetTwoElementsGood[p][0], subsetTwoElementsGood[check][0], subsetTwoElementsGood[check][1]);
  84.                                 }
  85.                                 else
  86.                                 {
  87.                                     checkFirstTwo = int.Parse(subsetTwoElementsGood[p][1] + subsetTwoElementsGood[p][0]);
  88.                                     checkSecondTwo = int.Parse(subsetTwoElementsGood[check][1] + subsetTwoElementsGood[check][0]);
  89.                                     if ((checkFirstTwo == checkSecondTwo) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][1]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][1]))
  90.                                     {
  91.                                         Console.WriteLine("{0}|{1}={2}|{3}", subsetTwoElementsGood[p][1], subsetTwoElementsGood[p][0], subsetTwoElementsGood[check][1], subsetTwoElementsGood[check][0]);
  92.                                     }
  93.                                     else
  94.                                     {
  95.                                         checkFirstTwo = int.Parse(subsetTwoElementsGood[p][0] + subsetTwoElementsGood[p][1]);
  96.                                         checkSecondTwo = int.Parse(subsetTwoElementsGood[check][1] + subsetTwoElementsGood[check][0]);
  97.                                         if ((checkFirstTwo == checkSecondTwo) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][0] != subsetTwoElementsGood[check][1]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][0]) && (subsetTwoElementsGood[p][1] != subsetTwoElementsGood[check][1]))
  98.                                         {
  99.                                             Console.WriteLine("{0}|{1}={2}|{3}", subsetTwoElementsGood[p][0], subsetTwoElementsGood[p][1], subsetTwoElementsGood[check][1], subsetTwoElementsGood[check][0]);
  100.                                         }
  101.                                     }
  102.                                 }
  103.                             }
  104.                         }
  105.                    
  106.                 }
  107.                    
  108.             }
  109.             }// foreach
  110.             //subsetTwoElementsGood.ForEach(t => Console.WriteLine(string.Join("..", t)));
  111.         }
  112.     }
  113. }
  114. // Ugly
Advertisement
Add Comment
Please, Sign In to add comment