Fun permutations exercise from http://harry.garrood.me/blog/permutations-an-exercise/