// Calculates and returns the rook polynomial for the given board matrix public static Polynomial solve(Board board) { if (board.Count == 0) return new Polynomial(); int[] intersect = board.greatestIntersection; Polynomial x = new Polynomial(0, 1); return board.deleteCell(intersect[0], intersect[1]) + x * board.deleteRowCol(intersect[0], intersect[1]); }
// Plus operator: Polynomial + Polynomial public static Polynomial operator +(Polynomial ply1, Polynomial ply2) { ArrayList xs = new ArrayList(); for (int i = 0, j = 0; i < ply1.Count || j < ply2.Count; i++, j++) { try { xs.Add(ply1[i] + ply2[j]); } catch (ArgumentOutOfRangeException) { // xs.Add(0); if (i >= ply1.Count) xs.Add(ply2[j]); else if (j >= ply2.Count) xs.Add(ply1[i]); } } // xs.RemoveAt(0); Polynomial newply = new Polynomial(xs); return newply; }