Exemple #1
0
        public void GetScatterData()
        {
            Day10PointOfLight MaxXY;
            Day10PointOfLight MinXY;
            Day10PointOfLight MaxXMinY;
            Day10PointOfLight MinXMaxY;
            Day10Coord        average;

            MaxXY    = points.OrderBy(o1 => o1.X).ThenBy(o2 => o2.Y).First();
            MinXY    = points.OrderByDescending(o1 => o1.X).ThenByDescending(o2 => o2.Y).First();
            MaxXMinY = points.OrderBy(o1 => o1.X).ThenByDescending(o2 => o2.Y).First();
            MinXMaxY = points.OrderByDescending(o1 => o1.X).ThenBy(o2 => o2.Y).First();

            average = Day10PointOfLight.Average(new Day10PointOfLight[] { MaxXY, MinXY, MaxXMinY, MinXMaxY });

            StringBuilder sb = new StringBuilder();

            sb.Append("Average of max points: " + average.X.ToString() + ", " + average.Y.ToString() + Environment.NewLine + Environment.NewLine);
            sb.Append("   MaxXY: " + MaxXY.X + ", " + MaxXY.Y + Environment.NewLine);
            sb.Append("   MinXY: " + MinXY.X + ", " + MinXY.Y + Environment.NewLine);
            sb.Append("MaxXMinY: " + MaxXMinY.X + ", " + MaxXMinY.Y + Environment.NewLine);
            sb.Append("MinXMaxY: " + MinXMaxY.X + ", " + MinXMaxY.Y + Environment.NewLine);

            MessageBox.Show(sb.ToString());
        }
Exemple #2
0
        // Day10b is a natural solution of Day10a in this setup.  Actually, I'm not sure how you could solve a without also already knowing b.  Hmmm...
        public static string Day10a(int updates = 1, int by = 1, bool invert = false)
        {
            string[] lines;
            List <Day10PointOfLight> points = new List <Day10PointOfLight>();

            using (Stream stream = thisExe.GetManifestResourceStream("AdventOfCode2018._data.AdventOfCode_Day10.txt"))
                using (StreamReader reader = new StreamReader(stream))
                {
                    lines = StreamFunctions.EnumerateLines(reader).ToArray();
                }

            foreach (string line in lines)
            {
                Day10PointOfLight p = new Day10PointOfLight(line);
                points.Add(p);
            }

            Day10PointManager _mgr = new Day10PointManager(points);

            Stopwatch sw = new Stopwatch();

            points = _mgr.RunWork(updates, by);

            char[,] starArray = _mgr.GetStarArray();

            StringBuilder sb = new StringBuilder();

            if (invert)
            {
                for (int x = 0; x < starArray.GetLength(0); x++)
                {
                    for (int y = 0; y < starArray.GetLength(1); y++)
                    {
                        if (starArray[x, y] == '*')
                        {
                            sb.Append("*");
                        }
                        else
                        {
                            sb.Append(" ");
                        }
                    }
                    sb.Append(Environment.NewLine);
                }
            }

            else
            {
                for (int y = 0; y < starArray.GetLength(1); y++)
                {
                    for (int x = 0; x < starArray.GetLength(0); x++)
                    {
                        if (starArray[x, y] == '*')
                        {
                            sb.Append("*");
                        }
                        else
                        {
                            sb.Append(" ");
                        }
                    }
                    sb.Append(Environment.NewLine);
                }
            }
            //_mgr.GetScatterData();

            return(sb.ToString());

            #region Support Methods

            #endregion
        }