Solved problem 3 (with quite a bit of help... math is hard lol)