problem 3 solution, albeit built-in ruby method