Ejemplo n.º 1
0
        public static void Run(string[] input)
        {
            D7Graph g    = new D7Graph(input);
            string  root = part01(g);

            Console.WriteLine("Part 1: " + root);

            Console.WriteLine(get_unbalanced(g, g.children("ugml")));
        }
Ejemplo n.º 2
0
        static bool children_unbalanced(D7Graph g, string root)
        {
            HashSet <int> ws = new HashSet <int>();

            foreach (string c in g.children(root))
            {
                ws.Add(g.weight(c));
            }

            return(ws.Count > 1);
        }
Ejemplo n.º 3
0
        static int part02(D7Graph g, string root)
        {
            bool found = false;

            while (!found)
            {
                string[] targets = g.children(root);

                string unbalanced = get_unbalanced(g, targets);

                if (unbalanced == null)
                {
                    found = true;
                }
                else
                {
                    root = unbalanced;
                }
            }
        }