Solved question 3 in Ruby. Minimal and neat.