Solved problem 3 in Ruby, needs some work