David Finch's solution:
For completeness.