# Need help understanding problem with arrays

This is a discussion on Need help understanding problem with arrays within the C Programming forums, part of the General Programming Boards category; Hi guys, I'm reading this problem which I find quite confusing, here it is: "We are in 2100 and we ...

1. ## Need help understanding problem with arrays

Hi guys, I'm reading this problem which I find quite confusing, here it is:
"We are in 2100 and we can travel universe, the α1λ3 course links the Earth to Saturn and spaceships are obliged to follow it taking several years to get through it. In order to watch the spaceships in their course, the first day of each month of each year are calculated the covered light year distance from the earth, if the spaceship takes off from the earth, and the light year distance left to get to the earth if the spaceship takes off from Saturn. Suppose that the two spaceships travel at different velocity and have taken off at the same time, the first from the earth and the second from Saturn on the 1st of January of the same year ( N ), and have got to their destination the 1st of January of the year M1 the former, and the 1st of January of the year M2 the latter. (M1, M2 > N).
DA and DB are two arrays that contain the distances covered by the two spaceships, given the three years (N, M1, M2), find in which year and in which month the two spaceships have crossed each other.

Example:
for a given year N the two arrays are:
DA = [0, 0.5 , 0.7 , 1.2, 1.5, 2]
DB = [2, 1.7, 1.3, 0.9, 0.4, 0.24, 0]
and the two spaceships crossed in April (the 4th month) of the year N

Guys this is not an homework, I'm not asking anyone to solve it, I just need to understand the mathematical concept behind it, i made some graphs but I couldn't figure out its logic, any tip would be appreciate, thanks anyway

2. The best thing to do with these word problems, is to grab a pencil and paper, and draw them out. The basic equation to remember is:

Distance = Rate * Time

but here, they're giving you the distances traveled in each month, for each spaceship. That's your key. When the amount that has been traveled by the faster spaceship, is greater than the distance remaining for the slower spaceship, then the two spaceships have crossed.

Take a few "snapshots" of the spaceships along the way, their distances traveled, and the distance still to be traveled, and see if that makes sense.

3. If x1 is the distance from earth for DA traveling to Saturn and x2 be the distance traveled by DB, whose distance from earth is given by x2, then the distance traveled by DB from Saturn is given by : DISTANCE_BETWEEN_EARTH_AND_SATURN - x2.

When
(x1 + (DISTANCE_BETWEEN_EARTH_AND_SATURN - x2) >= DISTANCE_BETWEEN_EARTH_AND_SATURN)
the 2 space ships have crossed each other, but since statistics are available only at the beginning of each month,
for : DA[3] + (2 - DB[3]) >= 2
hence the 2 space ships have crossed each other.ie 4th month.

Hope i haven't misunderstood the question. Do you have more test cases.

4. I finally get it, it wasn't difficult at all, thanks again!!