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; }
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); }
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); }
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)); } }
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; }
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; } }
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; }