Added imperative solution to 8.
Functional refactor for problem 8.