Beispiel #1
0
        public static long Part2(BagRules rules)
        {
            if (rules == null)
            {
                throw new ArgumentNullException(nameof(rules));
            }

            return(rules.GetBagByColor("shiny gold").ContainedBags() - 1);
        }
Beispiel #2
0
        public static long Part1(BagRules rules)
        {
            if (rules == null)
            {
                throw new ArgumentNullException(nameof(rules));
            }

            return(rules.Bags.Where((bag) => bag.CanContain("shiny gold")).Count());
        }
Beispiel #3
0
        public static int Main(string[] args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            string filename = args.Length > 0 ? args[0] : "input.txt";

            if (!File.Exists(filename))
            {
                Console.Error.WriteLine($"File not found: {filename}");
                return(100);
            }

            BagRules rules = BagRules.FromString(File.ReadAllText(filename));

            Console.WriteLine(Solver.Part1(rules));
            Console.WriteLine(Solver.Part2(rules));

            return(0);
        }