Example #1
0
        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("");
            }
        }
Example #2
0
        public Arithmetic3x3 GenerateArithmetic3x3()
        {
            Random rand = new Random();
            int    num  = rand.Next(1, 9);
            List <ArithmeticExpression3> arithmeticsRow1 = GetArithmetics3(num);
            ArithmeticExpression3        row1            = arithmeticsRow1[rand.Next(0, arithmeticsRow1.Count - 1)];
            List <ArithmeticExpression3> arithmeticsCol1 = GetArithmetics3(row1.val1);
            ArithmeticExpression3        col1            = arithmeticsCol1[rand.Next(0, arithmeticsCol1.Count - 1)];
            List <ArithmeticExpression3> arithmeticsRow2 = GetArithmetics3(col1.val2);
            List <ArithmeticExpression3> arithmeticsRow3 = GetArithmetics3((int)col1.GetResult());
            List <ArithmeticExpression3> arithmeticsCol2 = GetArithmetics3(row1.val2);
            List <ArithmeticExpression3> arithmeticsCol3 = GetArithmetics3((int)row1.GetResult());
            List <Arithmetic3x3>         temp3x3         = new List <Arithmetic3x3>();

            foreach (ArithmeticExpression3 row2 in arithmeticsRow2)
            {
                foreach (ArithmeticExpression3 row3 in arithmeticsRow3)
                {
                    foreach (ArithmeticExpression3 col2 in arithmeticsCol2)
                    {
                        foreach (ArithmeticExpression3 col3 in arithmeticsCol3)
                        {
                            if (row2.val2 == col2.val2 && row2.GetResult() == col3.val2 &&
                                row3.val2 == col2.GetResult() && row3.GetResult() == col3.GetResult())
                            {
                                Arithmetic3x3 newArithmetic3x3 = new Arithmetic3x3();
                                newArithmetic3x3.rows    = new ArithmeticExpression3[3];
                                newArithmetic3x3.cols    = new ArithmeticExpression3[3];
                                newArithmetic3x3.rows[0] = row1;
                                newArithmetic3x3.rows[1] = row2;
                                newArithmetic3x3.rows[2] = row3;
                                newArithmetic3x3.cols[0] = col1;
                                newArithmetic3x3.cols[1] = col2;
                                newArithmetic3x3.cols[2] = col3;
                                temp3x3.Add(newArithmetic3x3);
                            }
                        }
                    }
                }
            }
            return(temp3x3[rand.Next(0, temp3x3.Count - 1)]);
        }