Actually, I spoke too soon.
I also posted the code to the Code snippets forum. Someone on there beat the computer with 5 - 3 - 9 - 1. That will happen every time because of the way the code fills up the next available horizontal space (its pretty basic in that respect).
Another chap kindly wrote an amendment to my code to fix that. The fix works but, without intending any offence to the chap, seems to have introduced a further bug.
I'll go back to the code at the weekend when I am not watching Wimbledon and fix the new bug.