Finish problem 5 in ruby