public static void Main(string[] args) { // Build up the board. // A board is a set of "subproblems" that piece together to form the entire "problem" // A subproblem would be, for example: s[0] = s[1] = ... = s[n] = SubProblem(Operator.Multiply, 18). // Meaning the squares 0 through n multiply to equal 18. Problem problem = new Problem(); problem.SubProblems[0, 0] = problem.SubProblems[0, 1] = problem.SubProblems[1, 1] = new SubProblem(Operator.Multiply, 18); problem.SubProblems[1, 0] = problem.SubProblems[2, 0] = problem.SubProblems[3, 0] = problem.SubProblems[4, 0] = problem.SubProblems[4, 1] = new SubProblem(Operator.Multiply, 5040); problem.SubProblems[5, 0] = new SubProblem(Operator.Constant, 7); problem.SubProblems[6, 0] = problem.SubProblems[7, 0] = new SubProblem(Operator.Divide, 2); problem.SubProblems[8, 0] = problem.SubProblems[8, 1] = problem.SubProblems[7, 1] = new SubProblem(Operator.Multiply, 180); problem.SubProblems[2, 1] = problem.SubProblems[2, 2] = problem.SubProblems[1, 2] = new SubProblem(Operator.Add, 17); problem.SubProblems[3, 1] = problem.SubProblems[3, 2] = new SubProblem(Operator.Add, 7); problem.SubProblems[5, 1] = problem.SubProblems[5, 2] = new SubProblem(Operator.Add, 17); problem.SubProblems[6, 1] = problem.SubProblems[6, 2] = new SubProblem(Operator.Divide, 4); problem.SubProblems[0, 2] = problem.SubProblems[0, 3] = problem.SubProblems[0, 4] = new SubProblem(Operator.Add, 15); problem.SubProblems[4, 2] = problem.SubProblems[4, 3] = problem.SubProblems[5, 3] = new SubProblem(Operator.Add, 13); problem.SubProblems[7, 2] = problem.SubProblems[8, 2] = problem.SubProblems[8, 3] = problem.SubProblems[8, 4] = new SubProblem(Operator.Multiply, 56); problem.SubProblems[1, 3] = problem.SubProblems[2, 3] = problem.SubProblems[3, 3] = new SubProblem(Operator.Multiply, 224); problem.SubProblems[6, 3] = problem.SubProblems[7, 3] = new SubProblem(Operator.Subtract, 8); problem.SubProblems[1, 4] = problem.SubProblems[1, 5] = problem.SubProblems[0, 5] = new SubProblem(Operator.Multiply, 126); problem.SubProblems[2, 4] = problem.SubProblems[2, 5] = new SubProblem(Operator.Subtract, 3); problem.SubProblems[3, 4] = problem.SubProblems[4, 4] = problem.SubProblems[5, 4] = new SubProblem(Operator.Multiply, 35); problem.SubProblems[6, 4] = problem.SubProblems[6, 5] = problem.SubProblems[5, 5] = new SubProblem(Operator.Add, 8); problem.SubProblems[7, 4] = problem.SubProblems[7, 5] = problem.SubProblems[8, 5] = new SubProblem(Operator.Add, 15); problem.SubProblems[3, 5] = problem.SubProblems[4, 5] = new SubProblem(Operator.Add, 17); problem.SubProblems[0, 6] = problem.SubProblems[1, 6] = problem.SubProblems[2, 6] = problem.SubProblems[3, 6] = new SubProblem(Operator.Multiply, 216); problem.SubProblems[4, 6] = new SubProblem(Operator.Constant, 1); problem.SubProblems[5, 6] = problem.SubProblems[6, 6] = problem.SubProblems[7, 6] = problem.SubProblems[8, 6] = new SubProblem(Operator.Add, 26); problem.SubProblems[0, 7] = problem.SubProblems[1, 7] = new SubProblem(Operator.Subtract, 1); problem.SubProblems[2, 7] = problem.SubProblems[3, 7] = new SubProblem(Operator.Add, 3); problem.SubProblems[4, 7] = problem.SubProblems[4, 8] = problem.SubProblems[3, 8] = problem.SubProblems[5, 8] = new SubProblem(Operator.Add, 23); problem.SubProblems[5, 7] = problem.SubProblems[6, 7] = new SubProblem(Operator.Divide, 2); problem.SubProblems[7, 7] = problem.SubProblems[8, 7] = new SubProblem(Operator.Subtract, 1); problem.SubProblems[0, 8] = problem.SubProblems[1, 8] = problem.SubProblems[2, 8] = new SubProblem(Operator.Add, 14); problem.SubProblems[6, 8] = problem.SubProblems[7, 8] = problem.SubProblems[8, 8] = new SubProblem(Operator.Multiply, 135); problem.Solve(); }
public Problem Prune(KenKenBoard board) { // Prune out solutions that are no longer valid // given the current board. Problem ret = new Problem(); ret.mAll = new List<SubProblem>(); for (int i = 1; i < mAll.Count; i++) { SubProblem sub = mAll[i]; SubProblem s = sub.Prune(board); // If there are no solutions for this pruned SubProblem, this Problem failed. if (s == null) return null; ret.mAll.Add(s); } return ret; }