示例#1
0
        private List <RightTriangle> ExpandMultiples(RightTriangle baseTri, int maxPerim)
        {
            List <RightTriangle> retVal = new List <RightTriangle>();

            retVal.Add(baseTri);
            int multiple = 2;

            while (true)
            {
                RightTriangle newTri = new RightTriangle(multiple * baseTri.a, multiple * baseTri.b, multiple * baseTri.c);
                if (newTri.GetPerimeter() <= maxPerim)
                {
                    retVal.Add(newTri);
                }
                else
                {
                    return(retVal);
                }
            }
        }
示例#2
0
        private List <RightTriangle> GetUnscaledRightTriangles(int maxPerim)
        {
            List <RightTriangle> retVal = new List <RightTriangle>();
            // using following method to generate triangles: [x2-y2]2 + [2xy]2 = [x2+y2]2
            int maxXOrY = (int)Math.Sqrt(maxPerim);

            for (int x = 2; x <= maxXOrY; x++)
            {
                for (int y = 1; y < x; y++)
                {
                    RightTriangle baseTri = GenerateFromXY(x, y);
                    if (!retVal.Any(m => m.a == baseTri.a && m.b == baseTri.b))
                    {
                        if (baseTri.GetPerimeter() <= maxPerim)
                        {
                            retVal.Add(baseTri);
                        }
                    }
                }
            }
            return(retVal);
        }