Example #1
0
        public static int FindMinManhattanDistance(Path wireOne, Path wireTwo)
        {
            var wireOneLocations = new HashSet <Location>(wireOne.GetLocationsFrom(Location.CentralPort).Select(l => l.Location));
            var wireTwoLocations = new HashSet <Location>(wireTwo.GetLocationsFrom(Location.CentralPort).Select(l => l.Location));

            var intersections = wireOneLocations
                                .Intersect(wireTwoLocations)
                                .ThatAreNotCentralPort();

            var minDistance = int.MaxValue;

            foreach (var intersection in intersections)
            {
                minDistance = Math.Min(minDistance, ManhattanDistance.FindDistance(Location.CentralPort, intersection));
            }

            return(minDistance);
        }
Example #2
0
        static void Main(string[] args)
        {
            ManhattanDistance     manhattanDistance = new ManhattanDistance();
            List <List <string> > locations         = manhattanDistance.GetLocations("wirestest.txt");

            int[] tests  = new[] { 6, 159, 135 };
            bool  passed = manhattanDistance.CrossLocation(locations, tests);

            if (passed)
            {
                List <List <string> > locations2 = manhattanDistance.GetLocations("wires.txt");
                int result = manhattanDistance.CrossLocation(locations2);
                Console.WriteLine($"result: {result}");
            }
            else
            {
                Console.WriteLine("failed");
            }
        }