Bit of a brute force approach with an iterative. Should work for small number of horses (before the N! explodes).
You can choose any number of horses:
and book, factorial calculation!
Now going for the extra credit! I was sleeping with this idea for a few days and finally had time to develop it today.☝️