Since this SE community is about golfing, I thought a golf-related challenge would be appropriate.
Normally, the objective of golf is to finish a hole (and consequently, the entire round) with the least amount of strokes. This is a simple version of golf: Play until you hole the ball and sum up your score. Finally subtract it from the total par and the resulting number indicates your score: 0 if you played exactly par, positive if you played worse and negative if you played better.
But in 1898 a guy named Dr. Frank Barney Gorton Stableford devised a new system of playing which was designed to be more forgiving. This system awards a number of points to a player, based on a relative rating per hole, called the stroke index (SI) which is based on a player rating called handicap. This limits the amount of points a player can lose per hole. Additionally, the handiccp ensures fair competition between players despite skill difference.
This format isn't used in professional golf, but can be found almost anywhere in amateur golf.
The scoring algorithm
For anyone unfamiliar with golf, the algorithm for scoring a hole based version is as follows.
Beginning with the hardest hole (rating 1) to the easiest one (rating 18), increase the stroke index of that hole by 1 and decrement the handicap. If you exhaust the handicap, stop. If you hit the easiest hole you wrap around to the hardest and continue. (Ex: stroke index for hcp
For every score on a hole, subtract it from the sum of par and stroke index and add 2 (formula:
(par + stroke index) - achieved score + 2). These are the stableford points received for that hole. Note that you cannot receive less than 0 points.
Sum up all the points. The resulting total is the total number of stableford points.
Thus, reaching 36 points is equivalent to playing exactly one's handicap, and more points are better.
Your task will be to calculate the total number of stableford points of an arbitrary golf round on an arbitrary golf course given a handicap.
You will be given a list of difficulty ratings, a list of pars, a list of scores and the handicap to use. You may order these arguments as you wish, but please state how you order them.
You may write a function ot program, input can be taken either as command line argument or function argument.
Output may either be printed to STDOUT or the return value of a function.
You may assume the following about the input:
- Every list will contain exactly 18 elements.
- The lists are orderd by hole: First element = info for first hole, etc.
- The handicap will be an integer between 0 and 54 inclusive.
- Pars will be between 3 and 7.
- The score is always a positive integer.
- The difficulty rating list will always be a permutation of
This is code golf, so the shortest answer in bytes wins.
Input: hcp: 0 difficulty: [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18] pars: [3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5] score: [3,3,3,3,4,4,4,4,4,4,4,4,4,4,5,5,5,5] Output: 36 Input: hcp: 15 difficulty: [9,3,1,13,11,17,15,7,5,18,14,10,4,6,12,16,8,2] pars: [4,4,4,3,5,4,3,4,4,4,3,4,4,4,5,3,5,4] score: [5,5,4,5,4,4,4,4,5,7,3,5,5,6,4,6,5,5] Output: 38 Input: hcp: 28 difficulty: [9,3,1,13,11,17,15,7,5,18,14,10,4,6,12,16,8,2] pars: [4,4,4,3,5,4,3,4,4,4,3,4,4,4,5,3,5,4] score: [5,5,5,6,3,7,3,6,5,8,4,6,7,8,4,7,6,5] Outut: 37 Input: hcp: 54 difficulty: [9,3,1,13,11,17,15,7,5,18,14,10,4,6,12,16,8,2] pars: [4,4,4,3,5,4,3,4,4,4,3,4,4,4,5,3,5,4] score: [9,10,9,10,9,10,9,10,9,10,9,10,9,10,9,10,9,10] Output: 3