private static int Solution1(string[] input) { TargetArea targetArea = new(input[0]); int xDirection = Math.Sign(targetArea.XFrom); int minX = Math.Min(Math.Abs(targetArea.XFrom), Math.Abs(targetArea.XFrom)); int xVelocity; for (xVelocity = 1; SequenceHelpers.TriangularNumber(xVelocity) < minX; xVelocity++) { } Point initialVelocity = new(xVelocity * xDirection, Math.Abs(targetArea.YFrom) - 1); (_, int height) = targetArea.WillProbeHit(initialVelocity); return(height); }
public void TriangularNumbers(int n, int expected) { int actual = SequenceHelpers.TriangularNumber(n); Assert.Equal(expected, actual); }
static int FuelCost(int n) => SequenceHelpers.TriangularNumber(n);