I am working on an Android application that needs to determine the current tee order based on scores in a round of golf. For those of you that don’t know, the tee order (or honors) is the order a player hits their ball from the tee based on who had the best (lowest) score from the previous hole (current hole-1). If there are ties, then I need to look at the current hole-2 …etc. until I have figured out the order, or checked all scores at which point I would use the order they started in. Once I figure out an order for a player, I would stop checking the scores for that player. The catch is that players can start on any hole. There can also be any number of holes. So if they start on hole 3, then they will end on hole 2. So they will get to hole 18 (Assuming an 18 hole course) and then wrap around and start on hole 1. If you need a better explanation, let me know and I’ll try.
Example data:
Holes: 9
Starting hole: 3
Player 1: 0,0,5,4,5,6,3,2,5
Player 2: 0,0,4,2,5,3,3,6,3
Player 3: 0,0,4,3,7,3,2,2,5
Assume the starting order is: Player 1, Player 2, Player 3
Example Output of the order after calculation:
Player 2, Player 3, Player 1
I have attacked this problem thinking it was going to be pretty easy but it is turning out to be harder than I thought. I have gone the iterative route starting by looping through each player, then looping through each players’ scores for the first hole that they all have a score on… etc but I am finding I have a lot of for loops and it is just becoming ugly with a ton of if statements. I was going to try a recursive solution but I wanted to see if anyone had any ideas about, while I take a short break from it. If anyone wants to see my code I currently am at work and testing it in PHP because we don’t have Java on my dev server so the code will be in PHP. But it will be easy enough to port to Java. Thanks for any and all help!
Edit: I should also note, that I will want to know this information at any time, whether they have finished the round or not. So if they start on hole 3 and have only played 2 holes then I need to account for the un-played holes. If that wasn’t obvious already…
You just need one loop.
Loop through the hole numbers (beginning with their starting hole and wrapping back to 1 if necessary).
At each hole, look up the players’ scores for that hole, and then update the current state of who has honors.