Check the picture below.
bear in mind that, if the right-triangle is an isosceles, is a 45-45-90 triangle, and if we split it from the "vertex" above perpendicular to the base, we end up with two more 45-45-90 triangles.
It depends on what level of classes you take, but algebra classes in college do tend to be harder than algebra classes in high school or middle school.
That would be M = 30G where M is in miles and G is in gallons.