solved Problem3 with Ruby