problem 10 solution using ruby