Resolution of exercise 5 in Ruby Language