Ejemplo n.º 1
0
        int PathLength(IndexedGraph <string, Orbit> orbits)
        {
            var youChain = new LinkedList <Orbit>();
            var sanChain = new LinkedList <Orbit>();

            var orbit = orbits["YOU"];

            while (orbit.Name != "COM")
            {
                orbit = orbits.GetParent(orbit);
                youChain.AddFirst(orbit);
            }

            orbit = orbits["SAN"];
            while (orbit.Name != "COM")
            {
                orbit = orbits.GetParent(orbit);
                sanChain.AddFirst(orbit);
            }

            while (youChain.First.Value == sanChain.First.Value)
            {
                youChain.RemoveFirst();
                sanChain.RemoveFirst();
            }

            return(youChain.Count + sanChain.Count);
        }
Ejemplo n.º 2
0
        int CalculateNodeDepth(IndexedGraph <string, Orbit> orbits)
        {
            foreach (var orbit in orbits.DepthFirstWalk())
            {
                if (orbit.Name != "COM")
                {
                    orbit.Depth = orbits.GetParent(orbit).Depth + 1;
                }
            }

            var total = 0;

            foreach (var orbit in orbits.DepthFirstWalk())
            {
                total += orbit.Depth;
            }

            return(total);
        }