private int GetTowerWeight(Day17Program root, ref int weight) { weight += root.progWeight; foreach (var child in root.GetChildren()) { GetTowerWeight(child, ref weight); } return(weight); }
private int FindTowerImbalance(Day17Program prog) { var tot = prog.GetChildren().Select(a => a.balanceWeight).Max() % prog.GetChildren().Select(a => a.balanceWeight).Min() == 0; if (tot == true) { var heaviest1 = prog.GetParent().GetChildren().Select(a => a).OrderByDescending(a => a.balanceWeight).First(); var lightest1 = prog.GetParent().GetChildren().Select(a => a).OrderBy(a => a.balanceWeight).First(); return(heaviest1.progWeight - (heaviest1.balanceWeight - lightest1.balanceWeight)); } return(FindTowerImbalance(prog.GetChildren().Select(a => a).OrderByDescending(a => a.balanceWeight).FirstOrDefault())); }
public void AssociateChild(Day17Program child) { this.progChildren.Add(child); }
public void AssociateParent(Day17Program parent) { this.progParent = parent; }