Ruby solution for problem 19