Problem 3 implementation

solution to problem 3