public static void Main(string[] args) { // check that arguments have been supplied if (args.Length != 2) { Console.WriteLine("missing args"); System.Environment.Exit(1); } // attempt to open data file InFile data = new InFile(args[0]); if (data.OpenError()) { Console.WriteLine("cannot open " + args[0]); System.Environment.Exit(1); } // attempt to open results file OutFile results = new OutFile(args[1]); if (results.OpenError()) { Console.WriteLine("cannot open " + args[1]); System.Environment.Exit(1); } // various initializations int total = 0; IntSet mySet = new IntSet(); IntSet smallSet = new IntSet(1, 2, 3, 4, 5); string smallSetStr = smallSet.ToString(); // read and process data file int item = data.ReadInt(); while (!data.NoMoreData()) { total = total + item; if (item > 0) { mySet.Incl(item); } item = data.ReadInt(); } // write various results to output file results.Write("total = "); results.WriteLine(total, 5); results.WriteLine("unique positive numbers " + mySet.ToString()); results.WriteLine("union with " + smallSetStr + " = " + mySet.Union(smallSet).ToString()); results.WriteLine("intersection with " + smallSetStr + " = " + mySet.Intersection(smallSet).ToString()); /* or simply * results.WriteLine("union with " + smallSetStr + " = " + mySet.Union(smallSet)); * results.WriteLine("intersection with " + smallSetStr + " = " + mySet.Intersection(smallSet)); */ results.Close(); } // Main
static IntSet[][] updateSuggestions() { IntSet[][] result = new IntSet[9][]; for (int i = 0; i < 9; i++) { result[i] = new IntSet[9]; for (int j = 0; j < 9; j++) { IntSet R = getRow(i); IntSet C = getCol(j); IntSet B = getBlock(i, j); IntSet union = R.Union(C).Union(B); IntSet suggestion = uSet.Difference(union); result[i][j] = suggestion; Console.WriteLine($"({i},{j}) -- " + suggestion.ToString()); } } return(result); }
private void PrintAndParse(IntSet set, string expect) { string s = set.ToString(); AreEqual(expect, s); AreEqual(IntSet.Parse(expect), set); }