Classic exercise in Ruby