My attempt at an exercise adapted from a problem by Julie Zelenski