A solution to a coding exercise in ruby