Solution to @haggismaths' question.