示例#1
0
        /// <summary>
        /// Runs First Task.
        /// </summary>
        /// <returns>Returns <see cref="SortedList{int, Triangle}"/></returns>
        /// <param name="path">Path to the file.</param>
        public SortedList <int, Triangle> FirstTask(string path)
        {
            try
            {
                TriangleManager        triangleManager = new TriangleManager();
                IEnumerable <Triangle> triangles       = triangleManager.Load(path);

                SortedList <int, Triangle> sortedTriangles = new SortedList <int, Triangle>();
                foreach (var triang in triangles)
                {
                    sortedTriangles.Add(triang.GetPerim(), triang);
                }

                foreach (var triang in sortedTriangles)
                {
                    Console.WriteLine(triang.Value);
                }

                return(sortedTriangles);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Runs Second Task.
        /// </summary>
        /// <param name="path">Path to the file.</param>
        /// <returns>Returns <see cref="Dictionary{Color, int}"/></returns>
        public Dictionary <Color, int> SecondTask(string path)
        {
            try
            {
                TriangleManager        triangleManager = new TriangleManager();
                IEnumerable <Triangle> triangles       = triangleManager.Load(path);
                var selectedTriangles = from triangle in triangles

                                        where
                                        (triangle.Sides[0].Color == triangle.Sides[1].Color &&
                                         triangle.Sides[0].Color == triangle.Sides[2].Color)
                                        group triangle by triangle.Sides[0].Color;


                Dictionary <Color, int> trianglesPairs = new Dictionary <Color, int>();
                foreach (IGrouping <Color, Triangle> g in selectedTriangles)
                {
                    trianglesPairs.Add(g.Key, g.Count());
                }

                foreach (var p in trianglesPairs)
                {
                    Console.WriteLine($"{p.Key} - {p.Value} items");
                }

                return(trianglesPairs);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Runs Third Task.
        /// </summary>
        /// <param name="path">Path to the file.</param>
        /// <returns>Returns <see cref="IEnumerable{Triangle}"/>.</returns>
        public IEnumerable <Triangle> ThirdTask(string path)
        {
            try
            {
                TriangleManager        triangleManager = new TriangleManager();
                IEnumerable <Triangle> almostOneColor  = from triangle in triangleManager.Load(path)
                                                         where (triangle.GetSides()[0].Color == triangle.GetSides()[1].Color && triangle.GetSides()[2].Color != triangle.GetSides()[0].Color) ||
                                                         (triangle.GetSides()[0].Color == triangle.GetSides()[2].Color && triangle.GetSides()[1].Color != triangle.GetSides()[0].Color) ||
                                                         (triangle.GetSides()[1].Color == triangle.GetSides()[2].Color && triangle.GetSides()[0].Color != triangle.GetSides()[1].Color)
                                                         select triangle;
                foreach (var triangle in almostOneColor)
                {
                    ColorSide[] sides = triangle.GetSides();
                    if (sides[0].Color == sides[1].Color)
                    {
                        sides[2].Color = sides[0].Color;
                    }
                    else if (sides[1].Color == sides[2].Color)
                    {
                        sides[0].Color = sides[1].Color;
                    }
                    else
                    {
                        sides[1].Color = sides[2].Color;
                    }

                    triangle.SetSides(sides[0], sides[1], sides[2]);
                    Console.WriteLine(triangle);
                }

                return(almostOneColor);
            }
            catch (Exception)
            {
                throw;
            }
        }