using System.Text.RegularExpressions;
class Program {
static void Main()
{
string input = File.ReadAllText(@"../../../../Input.in");
var validY = CrunchTheNumbers(input);
Console.WriteLine("The highest value for y is " + validY.Max());
Console.WriteLine("There are " + validY.Count() + " valid initial velocities");
}
static IEnumerable<int> CrunchTheNumbers(string input)
{
var reg = Regex.Matches(input, "-?[0-9]+").Select(m => int.Parse(m.Value)).ToArray();
var (xMin, xMax, yMin, yMax) = (reg[0], reg[1], reg[2], reg[3]);
var (vxInitMin, vxInitMax, vyInitMin, vyInitMax) = (0, xMax, yMin, -yMin);
for (var vxInit = vxInitMin; vxInit <= vxInitMax; vxInit++)
{
for (var vyInit = vyInitMin; vyInit <= vyInitMax; vyInit++)
{
var (x, y, vx, vy) = (0, 0, vxInit, vyInit);
var maxY = 0;
while (x <= xMax && y >= yMin)
{
x += vx;
y += vy;
vy -= 1;
vx = Math.Max(0, vx - 1);
maxY = Math.Max(y, maxY);
if (x >= xMin && x <= xMax && y >= yMin && y <= yMax)
{
yield return maxY;
break;
}
}
}
}
}
}