Пример #1
0
 public static Set operator ++(Set operand)
 {
     var result = new Set(operand);
     for (var i = 0; i < result.Count; i++)
     {
         result[i] = !result[i];
         if (result[i])
             break;
     }
     return result;
 }
Пример #2
0
        private static void Second( )
        {
            var a = new Set(new int[] { 5, 11, 3, 7, 9, 8, 10 });
            var b = new Set(new int[] { 1, 2, 4, 3, 5, 11 });
            var c = new Set(new int[] { 4, 3, 7, 9, 6 });

            Console.WriteLine("A: {0}", a);
            Console.WriteLine("~B: {0}", ~b);
            Console.WriteLine("C: {0}", c);

            Console.WriteLine("A&~B&C: {0}", a & ~b & c);
            Console.WriteLine("{0}", ( ~( a & ~b & c | a & ~( b & c ) ) | ( ~( a & b ) & c & c ) ) & a & ~b);
        }
Пример #3
0
 private static void Fiveth( )
 {
     var k = 4;
     var set = new Set(new int[] { 1, 2, 3, 4, 5 });
     var permutCount = Factorial(k);
     var i = 0;
     foreach (var sub in set.SubPermutations(k))
     {
         Write(sub, " ");
         i++;
         if (i % permutCount == 0)
             Console.WriteLine();
     }
     Console.WriteLine("\r\n{0}", set.SubPermutations(k).Count);
 }
Пример #4
0
        private static void Third( )
        {
            var set = new Set(new int[] { 1, 2, 3, 4, 5 });

            //WriteLine(set.SubSets().Select(i => i.ToBoleanString()));
            WriteLine(set.SubSets());
            //WriteLine(set.SubSetsGray().Select(i => i.ToBoleanString()));
            WriteLine(set.SubSetsGray());
            Console.WriteLine();

            var countOn = set.CountOn();
            for (var i = 0; i < countOn; i++)
            {
                //WriteLine(set.SubSets(i).Select(s => s.ToBoleanString()));
                WriteLine(set.SubSets(i));
            }
        }
Пример #5
0
 protected static void IterateSubsets(Set tmp)
 {
     for (var j = 0; j < tmp.Count; j++)
     {
         if (tmp[j] && !tmp[j + 1])
         {
             if (j + 2 < tmp.Count)
             {
                 tmp[j] = false;
                 tmp[j + 1] = true;
                 break;
             }
             else
             {
                 for (j--; j > 0; j--)
                     if (tmp[j] && !tmp[j + 1])
                     {
                         if (j + 2 < tmp.Count)
                         {
                             tmp[j] = false;
                             tmp[j + 1] = true;
                             tmp[j + 2] = true;
                             break;
                         }
                     }
                 break;
             }
         }
     }
     tmp[tmp.current.LastIndexOf(true) + 1] = true;
 }
Пример #6
0
 protected static void IterateLast(Set tmp, List<Set> result)
 {
     for (var index = tmp.current.FindLastIndex(b => b); index < tmp.Count; index++)
     {
         tmp[index] = true;
         result.Add(tmp.Clone());
         tmp[index] = false;
     }
 }
Пример #7
0
 protected Set Copy(bool useParrent)
 {
     Set t;
     if (useParrent)
         t = new Set(new int[0], this.parrent);
     else
         t = new Set(new int[0], this.ToList());
     return t;
 }