implemented solution to problem 6
pulled out some variables
added test for problem 6