implemented solution to problem 5
added test for problem 5