Solution to rainfall problem in Ruby