Skip to content

Commit 6dd0e3b

Browse files
BNAndraskahgoh
andauthored
Add darts (#539)
* Add `darts` * Create test template for darts --------- Co-authored-by: Kah Goh <[email protected]>
1 parent b63443d commit 6dd0e3b

File tree

14 files changed

+220
-0
lines changed

14 files changed

+220
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,14 @@
582582
"practices": [],
583583
"prerequisites": [],
584584
"difficulty": 3
585+
},
586+
{
587+
"slug": "darts",
588+
"name": "Darts",
589+
"uuid": "c6b23754-4410-4450-81fc-a7d53278cff5",
590+
"practices": [],
591+
"prerequisites": [],
592+
"difficulty": 2
585593
}
586594
]
587595
},
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Instructions
2+
3+
Calculate the points scored in a single toss of a Darts game.
4+
5+
[Darts][darts] is a game where players throw darts at a [target][darts-target].
6+
7+
In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands:
8+
9+
![Our dart scoreboard with values from a complete miss to a bullseye](https://assets.exercism.org/images/exercises/darts/darts-scoreboard.svg)
10+
11+
- If the dart lands outside the target, player earns no points (0 points).
12+
- If the dart lands in the outer circle of the target, player earns 1 point.
13+
- If the dart lands in the middle circle of the target, player earns 5 points.
14+
- If the dart lands in the inner circle of the target, player earns 10 points.
15+
16+
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.
17+
Of course, they are all centered at the same point — that is, the circles are [concentric][] defined by the coordinates (0, 0).
18+
19+
Given a point in the target (defined by its [Cartesian coordinates][cartesian-coordinates] `x` and `y`, where `x` and `y` are [real][real-numbers]), calculate the correct score earned by a dart landing at that point.
20+
21+
## Credit
22+
23+
The scoreboard image was created by [habere-et-dispertire][habere-et-dispertire] using [Inkscape][inkscape].
24+
25+
[darts]: https://en.wikipedia.org/wiki/Darts
26+
[darts-target]: https://en.wikipedia.org/wiki/Darts#/media/File:Darts_in_a_dartboard.jpg
27+
[concentric]: https://mathworld.wolfram.com/ConcentricCircles.html
28+
[cartesian-coordinates]: https://www.mathsisfun.com/data/cartesian-coordinates.html
29+
[real-numbers]: https://www.mathsisfun.com/numbers/real-numbers.html
30+
[habere-et-dispertire]: https://exercism.org/profiles/habere-et-dispertire
31+
[inkscape]: https://en.wikipedia.org/wiki/Inkscape
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"authors": [
3+
"BNAndras"
4+
],
5+
"contributors": [
6+
"kahgoh"
7+
],
8+
"files": {
9+
"solution": [
10+
"darts.ml"
11+
],
12+
"test": [
13+
"test.ml"
14+
],
15+
"example": [
16+
".meta/example.ml"
17+
],
18+
"editor": [
19+
"darts.mli"
20+
]
21+
},
22+
"blurb": "Calculate the points scored in a single toss of a Darts game.",
23+
"source": "Inspired by an exercise created by a professor Della Paolera in Argentina"
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let score (x: float) (y: float): int =
2+
let distance: float = sqrt((x ** 2.0) +. (y ** 2.0)) in
3+
if distance <= 1.0 then
4+
10
5+
else if distance <= 5.0 then
6+
5
7+
else if distance <= 10.0 then
8+
1
9+
else
10+
0
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[9033f731-0a3a-4d9c-b1c0-34a1c8362afb]
13+
description = "Missed target"
14+
15+
[4c9f6ff4-c489-45fd-be8a-1fcb08b4d0ba]
16+
description = "On the outer circle"
17+
18+
[14378687-ee58-4c9b-a323-b089d5274be8]
19+
description = "On the middle circle"
20+
21+
[849e2e63-85bd-4fed-bc3b-781ae962e2c9]
22+
description = "On the inner circle"
23+
24+
[1c5ffd9f-ea66-462f-9f06-a1303de5a226]
25+
description = "Exactly on center"
26+
27+
[b65abce3-a679-4550-8115-4b74bda06088]
28+
description = "Near the center"
29+
30+
[66c29c1d-44f5-40cf-9927-e09a1305b399]
31+
description = "Just within the inner circle"
32+
33+
[d1012f63-c97c-4394-b944-7beb3d0b141a]
34+
description = "Just outside the inner circle"
35+
36+
[ab2b5666-b0b4-49c3-9b27-205e790ed945]
37+
description = "Just within the middle circle"
38+
39+
[70f1424e-d690-4860-8caf-9740a52c0161]
40+
description = "Just outside the middle circle"
41+
42+
[a7dbf8db-419c-4712-8a7f-67602b69b293]
43+
description = "Just within the outer circle"
44+
45+
[e0f39315-9f9a-4546-96e4-a9475b885aa7]
46+
description = "Just outside the outer circle"
47+
48+
[045d7d18-d863-4229-818e-b50828c75d19]
49+
description = "Asymmetric position between the inner and middle circles"

exercises/practice/darts/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
default: clean test
2+
3+
test:
4+
dune runtest
5+
6+
clean:
7+
dune clean
8+
9+
.PHONY: clean

exercises/practice/darts/darts.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
let score (x: float) (y: float): int =
2+
failwith "Please implement 'score'"

exercises/practice/darts/darts.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val score : float -> float -> int

exercises/practice/darts/dune

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(executable
2+
(name test)
3+
(libraries base ounit2))
4+
5+
(alias
6+
(name runtest)
7+
(deps (:x test.exe))
8+
(action (run %{x})))
9+
10+
(alias
11+
(name buildtest)
12+
(deps (:x test.exe)))
13+
14+
(env
15+
(dev
16+
(flags (:standard -warn-error -A))))

exercises/practice/darts/dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.1)

0 commit comments

Comments
 (0)