Example #1
0
 public static int Solve2(Tree tree, string target = "shiny gold") =>
 BFSSum(target, tree);
Example #2
0
 public static int Solve1(Tree tree, string target = "shiny gold") =>
 tree
 .Select(edge => edge.Key)
 .Where(node => BFSFind(node, tree, target))
 .Count() - 1;
Example #3
0
 public static int BFSSum(string node, Tree tree) =>
 tree[node].Count() == 0
         ? 0
         : tree[node].Sum(x => (1 + BFSSum(x.Name, tree)) * x.Count);
Example #4
0
 public static bool BFSFind(string node, Tree tree, string target) =>
 node.Equals(target)
         ? true
         : tree[node]
 .Select(x => x.Name)
 .Any(x => BFSFind(x, tree, target));