Ejemplo n.º 1
0
        /// <summary>
        /// Execution function for Day 3
        /// </summary>
        public void Execute3()
        {
            UserActionAsync(() =>
            {
                WriteToConsole("Start execution of Day3");
                var parser = GetInputParser("Day3Input.txt");

                var startingPoint = new CoordinatePoint(0, 0);
                var wires         = parser.GetInputData().Select(line => new Wire(startingPoint, line.Split(','))).ToList();

                var wire1 = wires[0];
                var wire2 = wires[1];

                var intersections = wire1.GetIntersectionsWith(wire2);
                var board         = new GridBoard();
                var closestPoint  = board.GetClosestPointTo(intersections, startingPoint);

                WriteToConsole($"The closest intersection point is located at {closestPoint.point} with a distance to the starting point of {closestPoint.distance}");

                AddEmptyLine();

                WriteToConsole($"Now we want to find the closest intersection based on the steps both wires combined have to take to reach it");

                var firstIntersection = wire1.GetFirstIntersectionWith(wire2);

                WriteToConsole($"The first intersection point is located at {firstIntersection.point} with a total number of {firstIntersection.steps} steps");

                AddEmptyLine();
            });
        }
Ejemplo n.º 2
0
        public void DistanceAndStepTest(List <string> wire1, List <string> wire2, int distance, int steps)
        {
            var startingPoint = new CoordinatePoint(0, 0);

            var w1 = new Wire(startingPoint, wire1);
            var w2 = new Wire(startingPoint, wire2);

            var intersections = w1.GetIntersectionsWith(w2);

            var board        = new GridBoard();
            var closestPoint = board.GetClosestPointTo(intersections, startingPoint);

            var firstIntersection = w1.GetFirstIntersectionWith(w2);

            Assert.IsTrue(closestPoint.distance == distance);
            Assert.IsTrue(firstIntersection.steps == steps);
        }