Example #1
0
        public static void Generate(int A_from, int A_to, int B_from, int B_to, int C_from, int C_to, ref sq_eq[] eq, int num, bool zero, bool one, bool two, bool int_only)
        {
            int        count = 0;
            List <int> As    = new List <int>();
            List <int> Bs    = new List <int>();
            List <int> Cs    = new List <int>();
            List <ABC> abc   = new List <ABC>();

            for (int i = 0; i < A_to - A_from; ++i)
            {
                As.Add(i + A_from);
            }
            for (int i = 0; i < B_to - B_from; ++i)
            {
                Bs.Add(i + B_from);
            }
            for (int i = 0; i < C_to - C_from; ++i)
            {
                Cs.Add(i + C_from);
            }

            do
            {
                int a;
                int b;
                int c;
                do
                {
                    a = As[gen.Next() % As.Count];
                    b = Bs[gen.Next() % Bs.Count];
                    c = Cs[gen.Next() % Cs.Count];
                }while (abc.Contains(new ABC(a, b, c)));

                abc.Add(new ABC(a, b, c));

                double[] roots = SquareSolver.Solve(a, b, c);

                if ((((zero) && (roots.Length == 0)) ||
                     ((one) && (roots.Length == 1)) ||
                     ((two) && (roots.Length == 2))) &&
                    ((int_only == false) || ((int_only == true) && (roots[0] % 1 == 0) && (roots[1] % 1 == 0))))
                {
                    sq_eq eq_solve = new sq_eq(a, b, c, roots);
                    eq[count] = eq_solve;
                    ++count;
                }
            }while (count != num);
        }
Example #2
0
        private void sq_generate_button_Click(object sender, EventArgs e)
        {
            int A_from = int.Parse(sq_A_from.Text);
            int B_from = int.Parse(sq_B_from.Text);
            int C_from = int.Parse(sq_C_from.Text);
            int A_to   = int.Parse(sq_A_to.Text);
            int B_to   = int.Parse(sq_B_to.Text);
            int C_to   = int.Parse(sq_C_to.Text);

            bool zero         = sq_generate_0_root.Checked;
            bool one          = sq_generate_1_root.Checked;
            bool two          = sq_generate_2_root.Checked;
            bool only_integer = sq_only_integer.Checked;

            int num = int.Parse(sq_num2gen.Text);

            sq_eq[] equs = new sq_eq[num];
            SquareGenerator.Generate(A_from, A_to, B_from, B_to, C_from, C_to, ref equs, num, zero, one, two, only_integer);
            SquareGenerator.Output(equs, ref main_output);
        }