A rather imperative solution to 4.