ruby solution for second problem