public void Add(SnailFishPairEquation other) { foreach (var element in other.AllElaments) { AllElaments.Add(element); } foreach (var element in AllElaments) { element.Depth++; } var newRoot = new SnailFishElement(null); newRoot.LeftChild = Root; newRoot.RightChild = other.Root; Root.Parent = newRoot; other.Root.Parent = newRoot; Root = newRoot; AllElaments.Add(newRoot); }
public void Part2(string[] lines) { long maxMagnitude = 0; for (int i = 0; i < lines.Length; i++) { for (int j = 0; j < lines.Length; j++) { if (i == j) { continue; } var first = new SnailFishPairEquation(lines[i]); var second = new SnailFishPairEquation(lines[j]); first.Add(second); first.Reduce(); maxMagnitude = Math.Max(maxMagnitude, first.Root.Magnitude()); } } Console.WriteLine("Max magnitude of pairs :{0}", maxMagnitude); }