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); }
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); }