Esempio n. 1
0
        public static void Solve()
        {
            var    file = new StreamReader(@"/Users/rbakken/RiderProjects/AdventOfCode/AdventOfCode/Day7/day_7.txt");
            string line;
            var    bagDefinitions = new Dictionary <string, ColoredBag>();

            while ((line = file.ReadLine()) != null)
            {
                string[] rulePartitions = line.Split(new[] { "contain" }, StringSplitOptions.None);
                Dictionary <string, int> containedBags = ParseContainedBags(rulePartitions[1]);
                string     color         = ParseColor(rulePartitions[0], 0, 1);
                ColoredBag bagDefinition = CreateBagDefinition(color, containedBags);

                bagDefinitions.Add(color, bagDefinition);
            }

            Console.WriteLine($"Total Bags: {bagDefinitions["shiny gold"].TotalContainedBags(bagDefinitions)}");
        }
Esempio n. 2
0
        public static void Solve()
        {
            var    file = new StreamReader(@"/Users/rbakken/RiderProjects/AdventOfCode/AdventOfCode/Day7/day_7.txt");
            string line;
            var    bagDefinitions = new Dictionary <string, ColoredBag>();

            while ((line = file.ReadLine()) != null)
            {
                string[] rulePartitions = line.Split(new[] { "contain" }, StringSplitOptions.None);
                Dictionary <string, int> containedBags = ParseContainedBags(rulePartitions[1]);
                string     color         = ParseColor(rulePartitions[0], 0, 1);
                ColoredBag bagDefinition = CreateBagDefinition(color, containedBags);

                bagDefinitions.Add(color, bagDefinition);
            }

            int canContainShinyGold = bagDefinitions.Count(kvp => kvp.Value.CanContainBag("shiny gold", bagDefinitions));

            Console.WriteLine($"Can contain shiny gold: {canContainShinyGold}");
        }