solve problem #7 (using ruby std lib)