Solved #7 in ruby.