Attempted solution for Problem 3