Solution for C# (part 2).
Just wanted to finish it, so don't expect any beauty :) :
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Text;namespaceAdventOfCode2020{staticclassDay7Part2{staticList<string>input=newList<string>(File.ReadAllLines("//inputfile"));staticList<Bag>bagtypes=newList<Bag>();staticintcountbags=0;publicstaticvoidExecute(){//First make a list of the Bag classforeach(varruleininput){bagtypes.Add(DefineColorsForBag(rule));}//Get the shinygoldbagvarshinygoldbag=bagtypes.Where(x=>x.OwnColor=="shinygold").FirstOrDefault();//And then count the bagsCountBags(shinygoldbag,1);Console.WriteLine($"Answer: {countbags}");}privatestaticvoidCountBags(Bagbag,inttimes){foreach(varruleinbag.ContainerRules){//Count is used to add to the total and to set the times in the next recursionvarcount=rule.number*times;countbags+=count;vargetBagForRuleColor=bagtypes.Where(x=>x.OwnColor==rule.color).ToList();if(getBagForRuleColor.Count()==1)CountBags(getBagForRuleColor[0],count);}}privatestaticBagDefineColorsForBag(stringrule){varsplitrule1=rule.Split('');varbag=newBag(splitrule1[0]+splitrule1[1]);varsplitrule2=rule.Split('').Skip(3).ToArray();inti=0;while(true){varstringToCompare=splitrule2[i];if(stringToCompare.Contains(".")||string.Equals("no",stringToCompare))returnbag;if(stringToCompare.Contains(',')||stringToCompare.Contains("bag")||string.Equals("contain",stringToCompare)){i++;stringToCompare=splitrule2[i];if(string.Equals("no",stringToCompare)||string.Equals("0",stringToCompare))returnbag;int.TryParse(stringToCompare,outintt);bag.ContainerRules.Add(newRule(t,splitrule2[i+1]+splitrule2[i+2]));i+=3;}}returnbag;}}}
`
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Solution for C# (part 2).
Just wanted to finish it, so don't expect any beauty :) :
`