Solution to 016 in Ruby