private void ProcessEvalList() { // Get the index from the list if (EvalList.Count > 0) { Counter++; int index = EvalList.Dequeue(); // Get the bag Bag bag = BagList[index]; // enqueue the bag's contents' indices to the EvalList as many times as stated in the rule foreach (var item in bag.Containers) { if (item != "no other bag") { int amt = Int32.Parse(item[0].ToString()); string word = item.Trim('1', '2', '3', '4', '5', '6', ' '); for (int i = 0; i < amt; i++) { Bag thing = BagList.Where(x => x.Name == word).FirstOrDefault(); EvalList.Enqueue(BagList.IndexOf(BagList.Where(x => x.Name == word).FirstOrDefault())); } } } } }
private bool HandyHaversacksPartTwo() { ClearProperties(); bool hhTwo = true; while (hhTwo) { RuleList = CreateRuleList(); CreateBagListFromRulesTwo(); Console.WriteLine("Which bag would you like to begin evaluating?"); string bagToEval = Console.ReadLine(); EvalList.Enqueue(GetBagIndex(bagToEval)); do { ProcessEvalList(); } while (EvalList.Count() > 0); Console.WriteLine(Counter - 1); hhTwo = false; } return(false); }