improve ruby soln to p13