Ruby solution to S1C1