my solution

Here is a solution, dunno if it is the most elegant CC @lindseydew