problem 6 solution with passing tests