public Arithmetic4x4 GenerateArithmetic4x4() { Random rand = new Random(); int num = rand.Next(1, 9); List <ArithmeticExpression4> tempList; tempList = GetArithmetics4(num); ArithmeticExpression4 row1 = tempList[rand.Next(0, tempList.Count - 1)]; tempList = GetArithmetics4(row1.val1); ArithmeticExpression4 col1 = tempList[rand.Next(0, tempList.Count - 1)]; tempList = GetArithmetics4(row1.val2); ArithmeticExpression4 col2 = tempList[rand.Next(0, tempList.Count - 1)]; tempList = GetArithmetics4(col1.val2, col2.val2); ArithmeticExpression4 row2 = tempList[rand.Next(0, tempList.Count - 1)]; List <ArithmeticExpression4> rows3 = GetArithmetics4(col1.val3, col2.val3); List <ArithmeticExpression4> rows4 = GetArithmetics4((int)col1.GetResult(), (int)col2.GetResult()); List <ArithmeticExpression4> cols3 = GetArithmetics4(row1.val3, row2.val3); List <ArithmeticExpression4> cols4 = GetArithmetics4((int)row1.GetResult(), (int)row2.GetResult()); List <Arithmetic4x4> results = new List <Arithmetic4x4>(); foreach (ArithmeticExpression4 row3 in rows3) { foreach (ArithmeticExpression4 row4 in rows4) { foreach (ArithmeticExpression4 col3 in cols3) { foreach (ArithmeticExpression4 col4 in cols4) { if (row3.val3 == col3.val3 && row3.GetResult() == col4.val3 && row4.val3 == col3.GetResult() && row4.GetResult() == col4.GetResult()) { Arithmetic4x4 newArithmetic4x4 = new Arithmetic4x4(); newArithmetic4x4.rows = new ArithmeticExpression4[4]; newArithmetic4x4.cols = new ArithmeticExpression4[4]; newArithmetic4x4.rows[0] = row1; newArithmetic4x4.rows[1] = row2; newArithmetic4x4.rows[2] = row3; newArithmetic4x4.rows[3] = row4; newArithmetic4x4.cols[0] = col1; newArithmetic4x4.cols[1] = col2; newArithmetic4x4.cols[2] = col3; newArithmetic4x4.cols[3] = col4; results.Add(newArithmetic4x4); } } } } } return(results[rand.Next(0, results.Count - 1)]); }
static void Main(string[] args) { TaskGenerator taskGenerator = new TaskGenerator(); for (int i = 0; i < 20; i++) { Arithmetic3x3 arithmetic3x3 = taskGenerator.GenerateArithmetic3x3(); Console.WriteLine(arithmetic3x3.ToString()); Console.WriteLine(""); } for (int i = 0; i < 20; i++) { Arithmetic4x4 arithmetic4x4 = taskGenerator.GenerateArithmetic4x4(); Console.WriteLine(arithmetic4x4.ToString()); Console.WriteLine(""); } }