Solve first problem of timus in ruby