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
124 lines
2.6 KiB
Markdown
124 lines
2.6 KiB
Markdown
---
|
|
id: 69a890af247de743333bd4cd
|
|
title: "Challenge 224: Coffee Roast Detector"
|
|
challengeType: 29
|
|
dashedName: challenge-224
|
|
---
|
|
|
|
# --description--
|
|
|
|
Given a string representing the beans used to make a cup of coffee, determine the roast of the cup.
|
|
|
|
- The given string will contain the following characters, each representing a type of bean:
|
|
|
|
- An apostrophe (`'`) is a light roast bean worth 1 point each.
|
|
- A dash (`-`) is a medium roast bean worth 2 points each.
|
|
- A period (`.`) is a dark roast bean worth 3 points each.
|
|
|
|
- The roast level is determined by the average of all the beans.
|
|
|
|
Return:
|
|
|
|
- `"Light"` if the average is less than 1.75.
|
|
- `"Medium"` if the average is 1.75 to 2.5.
|
|
- `"Dark"` if the average is greater than 2.5.
|
|
|
|
# --hints--
|
|
|
|
`detect_roast("''-''''''-'-''--''''")` should return `"Light"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(detect_roast("''-''''''-'-''--''''"), "Light")`)
|
|
}})
|
|
```
|
|
|
|
`detect_roast(".'-''-''..'''.-.-''-")` should return `"Medium"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(detect_roast(".'-''-''..'''.-.-''-"), "Medium")`)
|
|
}})
|
|
```
|
|
|
|
`detect_roast("--.''--'-''.--..-.--")` should return `"Medium"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(detect_roast("--.''--'-''.--..-.--"), "Medium")`)
|
|
}})
|
|
```
|
|
|
|
`detect_roast("-...'-......-..-...-")` should return `"Dark"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(detect_roast("-...'-......-..-...-"), "Dark")`)
|
|
}})
|
|
```
|
|
|
|
`detect_roast(".--.-..-......----.'")` should return `"Medium"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(detect_roast(".--.-..-......----.'"), "Medium")`)
|
|
}})
|
|
```
|
|
|
|
`detect_roast("..-..-..-..-....-.-.")` should return `"Dark"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(detect_roast("..-..-..-..-....-.-."), "Dark")`)
|
|
}})
|
|
```
|
|
|
|
`detect_roast("-'-''''''..-'.''-'.'")` should return `"Light"`.
|
|
|
|
```js
|
|
({test: () => { runPython(`
|
|
from unittest import TestCase
|
|
TestCase().assertEqual(detect_roast("-'-''''''..-'.''-'.'"), "Light")`)
|
|
}})
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```py
|
|
def detect_roast(beans):
|
|
|
|
return beans
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```py
|
|
def detect_roast(beans):
|
|
total = 0
|
|
|
|
for bean in beans:
|
|
if bean == "'":
|
|
total += 1
|
|
elif bean == "-":
|
|
total += 2
|
|
elif bean == ".":
|
|
total += 3
|
|
|
|
avg = total / len(beans)
|
|
|
|
if avg < 1.75:
|
|
return "Light"
|
|
elif avg <= 2.5:
|
|
return "Medium"
|
|
else:
|
|
return "Dark"
|
|
```
|