Skip to content

Commit 2eb93f6

Browse files
ramadisrpottsoh
authored andcommitted
Darts: Add new exercise (#1363)
1 parent f7f3659 commit 2eb93f6

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

exercises/darts/canonical-data.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"exercise": "darts",
3+
"version": "1.0.0",
4+
"cases": [
5+
{
6+
"description": "Return the correct amount earned by a dart landing in a given point in the target problem.",
7+
"cases": [
8+
{
9+
"property": "score",
10+
"description": "A dart lands outside the target",
11+
"input": {
12+
"x": 15.3,
13+
"y": 13.2
14+
},
15+
"expected": 0
16+
},
17+
{
18+
"property": "score",
19+
"description": "A dart lands just in the border of the target",
20+
"input": {
21+
"x": 10,
22+
"y": 0
23+
},
24+
"expected": 1
25+
},
26+
{
27+
"property": "score",
28+
"description": "A dart lands in the middle circle",
29+
"input": {
30+
"x": 3,
31+
"y": 3.7
32+
},
33+
"expected": 5
34+
},
35+
{
36+
"property": "score",
37+
"description": "A dart lands right in the border between outside and middle circles",
38+
"input": {
39+
"x": 0,
40+
"y": 5
41+
},
42+
"expected": 5
43+
},
44+
{
45+
"property": "score",
46+
"description": "A dart lands in the inner circle",
47+
"input": {
48+
"x": 0,
49+
"y": 0
50+
},
51+
"expected": 10
52+
}
53+
]
54+
}
55+
]
56+
}

exercises/darts/description.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Write a function that returns the earned points in a single toss of a Darts game.
2+
3+
[Darts](https://en.wikipedia.org/wiki/Darts) is a game where players
4+
throw darts to a [target](https://en.wikipedia.org/wiki/Darts#/media/File:Darts_in_a_dartboard.jpg).
5+
6+
In our particular instance of the game, the target rewards with 4 different amounts of points, depending on where the dart lands:
7+
8+
* If the dart lands outside the target, player earns no points (0 points).
9+
* If the dart lands in the outer circle of the target, player earns 1 point.
10+
* If the dart lands in the middle circle of the target, player earns 5 points.
11+
* If the dart lands in the inner circle of the target, player earns 10 points.
12+
13+
The outer circle has a radius of 10 units (This is equivalent to the total radius for the entire target), the middle circle a radius of 5 units, and the inner circle a radius of 1. Of course, they are all centered to the same point (That is, the circles are [concentric](http://mathworld.wolfram.com/ConcentricCircles.html)) defined by the coordinates (0, 0).
14+
15+
Write a function that given a point in the target (defined by its `real` cartesian coordinates `x` and `y`), returns the correct amount earned by a dart landing in that point.

exercises/darts/metadata.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
blurb: "Write a function that returns the earned points in a single toss of a Darts game"
3+
source: "Inspired by an excersie created by a professor Della Paolera in Argentina"

0 commit comments

Comments
 (0)