Solution:
Assume that your friend heads 20 ft east and then 15 ft south, and you head 12 ft west and 9 ft north.
The movement of your friend forms a right angle triangle with base of 20 ft and height of 15 ft
your movement forms a right angle triangle with base of 12 ft and height of 9 ft
The distance that the baseball is thrown is the sum of the hypotenuses of the right angle triangles formed
D = [ √(122 + 92) + √(202 + 152)] = 15 + 25 = 40 ft