private void fi_createField() { fi_cleanField(); System.Random rnd = new Random(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { mi_operants[x, y] = rnd.Next(1, 10); } } for (int x = 0; x < 3; x++) { for (int y = 0; y < 2; y++) { mi_vOperators[x, y] = fi_intToChar(rnd.Next(5)); mi_hOperators[x, y] = fi_intToChar(rnd.Next(5)); } } string text; ContainerList cl; for (int i = 0; i < 3; i++) { text = "" + mi_operants[i, 0] + mi_hOperators[i, 0] + mi_operants[i, 1] + mi_hOperators[i, 1] + mi_operants[i, 2]; cl = AContainer.Read(text); mi_hResults[i] = (int)cl.Calculate(); text = "" + mi_operants[0, i] + mi_vOperators[i, 0] + mi_operants[1, i] + mi_vOperators[i, 1] + mi_operants[2, i]; cl = AContainer.Read(text); mi_vResults[i] = (int)cl.Calculate(); } fi_updateCore(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { mi_operants[x, y] = 0; } } }
private void fi_solve() { List <Tuple <Constant, Constant, Constant> >[] possiblePairs = new List <Tuple <Constant, Constant, Constant> > [3]; for (int i = 0; i < possiblePairs.Length; i++) { possiblePairs[i] = new List <Tuple <Constant, Constant, Constant> >(); } ContainerList[] hor = new ContainerList[3]; for (int i = 0; i < 3; i++) { hor[i] = AContainer.Read($"{(char)(65 + 0 + 3 * i)}{mi_hOperators[i, 0]}{(char)(65 + 1 + 3 * i)}{mi_hOperators[i, 1]}{(char)(65 + 2 + 3 * i)}"); } double value; Constant c1, c2, c3; for (int first = 0; first < 10; first++) { for (int second = 0; second < 10; second++) { for (int third = 0; third < 10; third++) { for (int cl = 0; cl < hor.Length; cl++) { c1 = new Constant(((char)(65 + 0 + 3 * cl)).ToString(), first); c2 = new Constant(((char)(65 + 1 + 3 * cl)).ToString(), second); c3 = new Constant(((char)(65 + 2 + 3 * cl)).ToString(), third); hor[cl].SetConstants(c1); hor[cl].SetConstants(c2); hor[cl].SetConstants(c3); value = ((ContainerList)hor[cl].Clone()).Calculate(); if ((int)value == mi_hResults[cl]) { possiblePairs[cl].Add(new Tuple <Constant, Constant, Constant>(c1, c2, c3)); } } } } } ContainerList[] ver = new ContainerList[3]; int[] values = new int[3]; for (int i = 0; i < 3; i++) { string text = $"{(char)(65 + i + 3 * 0)}{mi_vOperators[i, 0]}{(char)(65 + i + 3 * 1)}{mi_vOperators[i, 1]}{(char)(65 + i + 3 * 2)}"; ver[i] = AContainer.Read(text); } for (int first = 0; first < possiblePairs[0].Count; first++) { for (int i = 0; i < 3; i++) { ver[i].SetConstants(possiblePairs[0][first].Item1, possiblePairs[0][first].Item2, possiblePairs[0][first].Item3); } for (int second = 0; second < possiblePairs[1].Count; second++) { for (int i = 0; i < 3; i++) { ver[i].SetConstants(possiblePairs[1][second].Item1, possiblePairs[1][second].Item2, possiblePairs[1][second].Item3); } for (int third = 0; third < possiblePairs[2].Count; third++) { for (int i = 0; i < 3; i++) { ver[i].SetConstants(possiblePairs[2][third].Item1, possiblePairs[2][third].Item2, possiblePairs[2][third].Item3); values[i] = (int)((ContainerList)ver[i].Clone()).Calculate(); } if (values[0] == mi_vResults[0] && (values[1] == mi_vResults[1]) && (values[2] == mi_vResults[2])) { mi_operants[0, 0] = (int)possiblePairs[0][first].Item1.mu_value; mi_operants[0, 1] = (int)possiblePairs[0][first].Item2.mu_value; mi_operants[0, 2] = (int)possiblePairs[0][first].Item3.mu_value; mi_operants[1, 0] = (int)possiblePairs[1][second].Item1.mu_value; mi_operants[1, 1] = (int)possiblePairs[1][second].Item2.mu_value; mi_operants[1, 2] = (int)possiblePairs[1][second].Item3.mu_value; mi_operants[2, 0] = (int)possiblePairs[2][third].Item1.mu_value; mi_operants[2, 1] = (int)possiblePairs[2][third].Item2.mu_value; mi_operants[2, 2] = (int)possiblePairs[2][third].Item3.mu_value; fi_updateOperants(); return; } } } } MessageBox.Show("there is no valid solution", "caution"); }