コード例 #1
0
        private int GetBagCount(Bags bag, ref List <Bags> bags)
        {
            int bagsAtThisLevel = 1;

            foreach (KeyValuePair <string, int> x in bag.containBags)
            {
                Bags nextBag = bags.First(y => y.BagColor.Equals(x.Key));

                bagsAtThisLevel = bagsAtThisLevel + (x.Value * GetBagCount(nextBag, ref bags));
            }

            return(bagsAtThisLevel);
        }
コード例 #2
0
ファイル: AOC2020Day07Part1.cs プロジェクト: FUNCTOR99/AOC
        private bool CanContainGold(Bags bag, ref List <Bags> bags)
        {
            bool foundShinyGold = false;

            foreach (KeyValuePair <string, int> x in bag.containBags)
            {
                if (x.Key.Equals("shiny gold"))
                {
                    return(true);
                }
                else
                {
                    Bags nextBag = bags.First(y => y.BagColor.Equals(x.Key));

                    if (CanContainGold(nextBag, ref bags))
                    {
                        foundShinyGold = true;
                    }
                }
            }

            return(foundShinyGold);
        }