static void Main(string[] args)
        {
            FileInputReader  reader  = new FileInputReader();
            DiscTowerFactory factory = new DiscTowerFactory(reader);
            DiscTower        tower   = factory.CreateFromInput("Inputs/day-7.txt");

            // Part one
            Console.WriteLine(tower.GetRootDisc().Name);

            // Part two
            Console.WriteLine(tower.FindBalancingProgramWeight());
        }
        public DiscTower CreateFromInput(string input)
        {
            DiscTower            tower = new DiscTower();
            IEnumerable <string> lines = _reader.ReadInput(input);

            foreach (string line in lines)
            {
                var parsedDisc = _extractDisc(line);
                var disc       = tower.GetDisc(parsedDisc.Name);

                if (disc != null)
                {
                    // If this disc is already in the tower, this means it is the child
                    // of some other disc, but now we know the weight of it.
                    disc.SetWeight(parsedDisc.Weight);
                }
                else
                {
                    disc = parsedDisc;

                    // If this disc isn't in the tower already, we'll want to add it.
                    tower.AddDisc(parsedDisc);
                }

                // If there are children for this disc, we will want to set up all the right
                // relationships.
                if (_hasChildren(line))
                {
                    var parsedChildren = _extractChildren(line);

                    foreach (DiscProgram child in parsedChildren)
                    {
                        var childDisc = tower.GetDisc(child.Name);

                        if (childDisc != null)
                        {
                            disc.AddChild(childDisc);
                        }
                        else
                        {
                            tower.AddDisc(child);
                            disc.AddChild(child);
                        }
                    }
                }
            }

            return(tower);
        }
        public void CreateDiscTowersFromInput()
        {
            string input = @"pbga (66)
                             xhth (57)
                             ebii (61)
                             havc (66)
                             ktlj (57)
                             fwft (72) -> ktlj, cntj, xhth
                             qoyq (66)
                             padx (45) -> pbga, havc, qoyq
                             tknk (41) -> ugml, padx, fwft
                             jptl (61)
                             ugml (68) -> gyxo, ebii, jptl
                             gyxo (61)
                             cntj (57)";

            StringInputReader reader  = new StringInputReader();
            DiscTowerFactory  factory = new DiscTowerFactory(reader);
            DiscTower         tower   = factory.CreateFromInput(input);

            Assert.Equal("tknk", tower.GetRootDisc().Name);
        }