Solution to 001 in Ruby