Resolution of exercise 4 in Ruby Language