コード例 #1
0
        public Task(Random rng, int paragraph, int tasks, int id)
        {
            task     = Task.tasks[paragraph - 1, id];
            this.rng = rng;
            for (int i = 0; i < tasks; i++)
            {
                switch (paragraph)
                {
                case 1:
                    Polynomials.Add(Task1(id));
                    break;

                case 2:
                    Polynomials.Add(Task2(id));
                    break;

                case 3:
                    Polynomials.Add(Task3(id));
                    break;

                case 4:
                    Polynomials.Add(Task4(id));
                    break;
                }
            }
        }
コード例 #2
0
        public void DoSomething()
        {
            var timer = new Stopwatch();

            timer.Start();
            Polynomials.Add(new HashSet <int[]>());
            for (var i = 1; i < N; i++)
            {
                if (File.Exists(@"Polynomials\" + i + ".txt"))
                {
                    var polynomials = File.ReadAllLines(@"Polynomials\" + i + ".txt");
                    Polynomials.Add(new HashSet <int[]>());
                    foreach (var polynomial in polynomials)
                    {
                        Polynomials[i].Add(polynomial.Select(x => int.Parse(x.ToString())).ToArray());
                    }
                }
                else
                {
                    DegreeCalculated = i;
                    break;
                }
            }
            if (DegreeCalculated == 0)
            {
                return;
            }

            for (var i = DegreeCalculated > 0 ? DegreeCalculated : 1; i <= N; i++)
            {
                var polynomial = new int[i + 1];

                ///У неприводимого многочлена младший коэффициент
                ///не может быть 0.
                for (int k = 1; k < field; ++k)
                {
                    polynomial[0] = k;
                    polynomial[polynomial.Length - 1] = 1;
                    Polynomials.Add(new HashSet <int[]>());
                    FindPolinomials(polynomial, 1);
                }
                var str = new StringBuilder();
                foreach (var irreducible in Polynomials[polynomial.Length - 1])
                {
                    str.Append(string.Join("", irreducible) + Environment.NewLine);
                }
                File.WriteAllText(@"Polynomials\" + i + ".txt", str.ToString());
                Console.WriteLine("Degree " + i + " calculated at " + DateTime.Now + " in "
                                  + timer.Elapsed + ". " + Polynomials[i].Count + " irreducible polynomials was found");
                timer.Restart();
            }
        }