/// <inheritdoc /> public string Part2() { int lowestCombinedSteps = int.MaxValue; for (int i = 0; i < lines1.Count; i++) { for (int j = 0; j < lines2.Count; j++) { Vector2Int intersection = LineInt.Intersects(lines1[i], lines2[j]); if (intersection != null) { int distance = Vector2Int.DistanceManhattan(Vector2Int.Zero, intersection); if (distance > 0) { int steps = Steps(i, j); steps += Vector2Int.DistanceManhattan(intersection, lines1[i].PointA); steps += Vector2Int.DistanceManhattan(intersection, lines2[j].PointA); if (steps != 0 && steps < lowestCombinedSteps) { lowestCombinedSteps = steps; Console.WriteLine($"new lowest: {lowestCombinedSteps}"); } } } } } return($"{lowestCombinedSteps}"); }
/// <inheritdoc /> public string Part1() { int lowestDistance = int.MaxValue; foreach (LineInt line1 in lines1) { foreach (LineInt line2 in lines2) { Vector2Int intersection = LineInt.Intersects(line1, line2); if (intersection != null) { int distance = Vector2Int.DistanceManhattan(Vector2Int.Zero, intersection); if (distance > 0 && distance < lowestDistance) { lowestDistance = distance; } } } } return($"{lowestDistance}"); }