Пример #1
0
        public long SolveCase2(long maxPerimeter)
        {
            var case2 = new GeneralQuadraticDiophatineEquationSolver()
            {
                A = 1,
                B = 0,
                C = -2,
                D = 2,
                E = 0,
                F = -2,
                r = 3,
                s = 2
            };

            //First solution
            long perimeterSum = 0;
            long xprev = 5;
            long yprev = (long)Math.Sqrt(Math.Pow(xprev, 2.0) - Math.Pow((xprev + 1) / 2, 2.0));

            long xnext, ynext;

            while ((3*xprev + 1) < maxPerimeter)
            {
                case2.Next(xprev, yprev, out xnext, out ynext);

                perimeterSum += 3 * xprev + 1;
                Console.WriteLine(xprev + "," + (xprev + 1));

                var a = xprev;
                var c = xprev + 1;
                var area = Math.Sqrt(c * c * (4 * a * a - c * c) / 16);
                Console.WriteLine(area);

                xprev = xnext;
                yprev = ynext;

            }

            return perimeterSum;
        }
Пример #2
0
        /* http://www.alpertron.com.ar/METHODS.HTM
         * Case 1: a - 1

         *
         * Ax^2 + Bxy + Cy^2 + Dx + Ey + F = 0
         *
         * a^2 - 2h^2 - 2a - 2 = 0
         * A = 1, B = 0, C = -2, D = -2, E = 0, F = -2
         *
         * a^2 - 2h^2 + 2a - 2 = 0
         * A = 1, B = 0, C = -2, D = 2, E = 0, F = -2

         */
        public long SolveCase1(long maxPerimeter)
        {
            // r*r + B*r*s + A*C*s*s = 1
            // r*r + -2*s*s = 1

            // 9 - 8
            // r = 3, s = 2 or -2

            var case1 = new GeneralQuadraticDiophatineEquationSolver()
            {
                A = 1,
                B = 0,
                C = -2,
                D = -2,
                E = 0,
                F = -2,
                r = 3,
                s = 2
            };

            long perimeterSum = 0;
            //First solution
            long xprev = 17;
            long yprev = (long)Math.Sqrt(Math.Pow(xprev, 2.0) - Math.Pow((xprev-1)/2, 2.0));

            long xnext,ynext;

            while ((3*xprev - 1) < maxPerimeter)
            {
                case1.Next(xprev, yprev, out xnext, out ynext);

                Console.WriteLine((xprev) + "," + (xprev - 1));

                var a = xprev;
                var c = xprev - 1;
                var area = Math.Sqrt(c * c * (4 * a * a - c * c) / 16);
                Console.WriteLine(area);

                perimeterSum += 3 * xprev - 1;

                xprev = xnext;
                yprev = ynext;

            }

            return perimeterSum;
        }