Ejemplo n.º 1
0
        public static void Part2(string[] data)
        {
            int totalBags = 0;
            Dictionary <string, Dictionary <string, int> > rules = new Dictionary <string, Dictionary <string, int> >();

            for (int i = 0; i < data.Length; i++)
            {
                Rule rule = new RuleParser(data[i]).CreateRule();
                rules.Add(rule.Bag, rule.Contains);
            }

            totalBags = CountNumBags(rules, "shiny gold");

            Console.WriteLine($"The number of bags contained within a Shiny Gold bag is: {totalBags}.");
        }
Ejemplo n.º 2
0
        public static void Part1(string[] data)
        {
            int totalBags = 0;
            Dictionary <string, Dictionary <string, int> > rules = new Dictionary <string, Dictionary <string, int> >();

            for (int i = 0; i < data.Length; i++)
            {
                Rule rule = new RuleParser(data[i]).CreateRule();
                rules.Add(rule.Bag, rule.Contains);
            }

            foreach (string bag in rules.Keys)
            {
                bool bagContainsShinyGold = DoesBagContainShinyGold(rules, bag);
                if (bagContainsShinyGold)
                {
                    totalBags++;
                }
            }

            Console.WriteLine($"The number of bags that can contain a shiny gold bag are: {totalBags}.");
        }