dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
79 lines
2.0 KiB
Markdown
79 lines
2.0 KiB
Markdown
---
|
|
id: 6a26df3e2988bcdded204895
|
|
title: "Challenge 359: Golf Handicap Calculator"
|
|
challengeType: 29
|
|
dashedName: challenge-359
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given an array of golf scores and a corresponding array of course par values, return the golfer's handicap index using the following method:
|
|
|
|
- Calculate the differential for each round by subtracting the par from the score, then return the average of all differentials rounded to one decimal place.
|
|
|
|
# --hints--
|
|
|
|
`calculate_handicap([72, 72, 72], [72, 72, 72])` should return `0`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(calculate_handicap([72, 72, 72], [72, 72, 72]), 0)`)
|
|
}})
|
|
```
|
|
|
|
`calculate_handicap([80, 76, 78, 78], [72, 72, 72, 72])` should return `6`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(calculate_handicap([80, 76, 78, 78], [72, 72, 72, 72]), 6)`)
|
|
}})
|
|
```
|
|
|
|
`calculate_handicap([42, 45, 46, 44], [36, 36, 36, 36])` should return `8.3`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(calculate_handicap([42, 45, 46, 44], [36, 36, 36, 36]), 8.3)`)
|
|
}})
|
|
```
|
|
|
|
`calculate_handicap([85, 80, 76, 79, 82], [72, 72, 72, 71, 71])` should return `8.8`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(calculate_handicap([85, 80, 76, 79, 82], [72, 72, 72, 71, 71]), 8.8)`)
|
|
}})
|
|
```
|
|
|
|
`calculate_handicap([41, 50, 48, 52, 46, 49], [35, 37, 35, 37, 35, 37])` should return `11.7`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(calculate_handicap([41, 50, 48, 52, 46, 49], [35, 37, 35, 37, 35, 37]), 11.7)`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def calculate_handicap(scores, pars):
|
|
|
|
return scores
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def calculate_handicap(scores, pars):
|
|
differentials = [s - p for s, p in zip(scores, pars)]
|
|
average = sum(differentials) / len(differentials)
|
|
return int(average * 10 + 0.5) / 10
|
|
```
|