Simon Bridge said:You have the basic idea - but the r in the gravity equation is the separation between the two objects, not their distance from the origin.
So if one object is at x1=4m from the origin, and the other is at x2=6m, in the same direction, then how far apart are they? 2m
if one is at x1=4m and the other at x2=x, in the same direction, then how far apart are they?x-4