Solved #10 in ruby.