problem 54 in Ruby