solve Problem#6 elegantly