Initial attempt
Refactored to simplify logic
Merge branch 'problem9'