001: solve in ruby and C++