Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add darts exercise #135

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,14 @@
"difficulty": 8
},
{
"slug": "darts",
"name": "Darts",
"uuid": "4fd80fde-8868-44da-a52b-f4b8549c9cc8",
"practices": [],
"prerequisites": [],
"difficulty": 1
},
}
"slug": "crypto-square",
"name": "Crypto Square",
"uuid": "5723544b-74d3-4483-b67e-5e7b513c8867",
Expand Down
31 changes: 31 additions & 0 deletions exercises/practice/darts/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Instructions

Calculate the points scored in a single toss of a Darts game.

[Darts][darts] is a game where players throw darts at a [target][darts-target].

In our particular instance of the game, the target rewards 4 different amounts of points, depending on where the dart lands:

![Our dart scoreboard with values from a complete miss to a bullseye](https://assets.exercism.org/images/exercises/darts/darts-scoreboard.svg)

- If the dart lands outside the target, player earns no points (0 points).
- If the dart lands in the outer circle of the target, player earns 1 point.
- If the dart lands in the middle circle of the target, player earns 5 points.
- If the dart lands in the inner circle of the target, player earns 10 points.

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 at the same point — that is, the circles are [concentric][] defined by the coordinates (0, 0).

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.

## Credit

The scoreboard image was created by [habere-et-dispertire][habere-et-dispertire] using [Inkscape][inkscape].

[darts]: https://en.wikipedia.org/wiki/Darts
[darts-target]: https://en.wikipedia.org/wiki/Darts#/media/File:Darts_in_a_dartboard.jpg
[concentric]: https://mathworld.wolfram.com/ConcentricCircles.html
[cartesian-coordinates]: https://www.mathsisfun.com/data/cartesian-coordinates.html
[real-numbers]: https://www.mathsisfun.com/numbers/real-numbers.html
[habere-et-dispertire]: https://exercism.org/profiles/habere-et-dispertire
[inkscape]: https://en.wikipedia.org/wiki/Inkscape
18 changes: 18 additions & 0 deletions exercises/practice/darts/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"authors": [
"eNascimento178"
],
"files": {
"solution": [
"darts.ijs"
],
"test": [
"test.ijs"
],
"example": [
".meta/example.ijs"
]
},
"blurb": "Calculate the points scored in a single toss of a Darts game.",
"source": "Inspired by an exercise created by a professor Della Paolera in Argentina"
}
1 change: 1 addition & 0 deletions exercises/practice/darts/.meta/example.ijs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
score=: 1 5 10&((0 ,~ |.@[) {~ I.)@([: | j./)
49 changes: 49 additions & 0 deletions exercises/practice/darts/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[9033f731-0a3a-4d9c-b1c0-34a1c8362afb]
description = "Missed target"

[4c9f6ff4-c489-45fd-be8a-1fcb08b4d0ba]
description = "On the outer circle"

[14378687-ee58-4c9b-a323-b089d5274be8]
description = "On the middle circle"

[849e2e63-85bd-4fed-bc3b-781ae962e2c9]
description = "On the inner circle"

[1c5ffd9f-ea66-462f-9f06-a1303de5a226]
description = "Exactly on center"

[b65abce3-a679-4550-8115-4b74bda06088]
description = "Near the center"

[66c29c1d-44f5-40cf-9927-e09a1305b399]
description = "Just within the inner circle"

[d1012f63-c97c-4394-b944-7beb3d0b141a]
description = "Just outside the inner circle"

[ab2b5666-b0b4-49c3-9b27-205e790ed945]
description = "Just within the middle circle"

[70f1424e-d690-4860-8caf-9740a52c0161]
description = "Just outside the middle circle"

[a7dbf8db-419c-4712-8a7f-67602b69b293]
description = "Just within the outer circle"

[e0f39315-9f9a-4546-96e4-a9475b885aa7]
description = "Just outside the outer circle"

[045d7d18-d863-4229-818e-b50828c75d19]
description = "Asymmetric position between the inner and middle circles"
3 changes: 3 additions & 0 deletions exercises/practice/darts/darts.ijs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'general/unittest'

score=: 'You need to implement this verb.'13!:8 (55)
152 changes: 152 additions & 0 deletions exercises/practice/darts/test.ijs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
load 'darts.ijs'


before_all=: monad define
(]Description =: (3 : 'descriptions=: i.0')`(3 : 'descriptions=: descriptions , < y'))@.0 ''
(]Order =: (3 : 'order=: i.0')`(3 : 'order=: order , < y'))@.0 ''
(]Task =: (3 : 'tasks=: i.0')`(3 : 'tasks=: tasks , < y'))@.0 ''
)


darts_test_01_ignore=: 0
test_darts_test_01 =: monad define
Description@.1 ('Missed target')
Order@.1 (1)

NB. x=. _9
NB. y=. 9
NB. expected=. 0
assert 0 -: score _9 9
)

darts_test_02_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_02 =: monad define
Description@.1 ('On the outer circle')
Order@.1 (2)

NB. x=. 0
NB. y=. 10
NB. expected=. 1
assert 1 -: score 0 10
)

darts_test_03_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_03 =: monad define
Description@.1 ('On the middle circle')
Order@.1 (3)

NB. x=. _5
NB. y=. 0
NB. expected=. 5
assert 5 -: score _5 0
)

darts_test_04_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_04 =: monad define
Description@.1 ('On the inner circle')
Order@.1 (4)

NB. x=. 0
NB. y=. _1
NB. expected=. 10
assert 10 -: score 0 _1
)

darts_test_05_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_05 =: monad define
Description@.1 ('Exactly on center')
Order@.1 (5)

NB. x=. 0
NB. y=. 0
NB. expected=. 10
assert 10 -: score 0 0
)

darts_test_06_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_06 =: monad define
Description@.1 ('Near the center')
Order@.1 (6)

NB. x=. _0.100000000000000006
NB. y=. _0.100000000000000006
NB. expected=. 10
assert 10 -: score _0.100000000000000006 _0.100000000000000006
)

darts_test_07_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_07 =: monad define
Description@.1 ('Just within the inner circle')
Order@.1 (7)

NB. x=. 0.699999999999999956
NB. y=. 0.699999999999999956
NB. expected=. 10
assert 10 -: score 0.699999999999999956 0.699999999999999956
)

darts_test_08_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_08 =: monad define
Description@.1 ('Just outside the inner circle')
Order@.1 (8)

NB. x=. 0.800000000000000044
NB. y=. _0.800000000000000044
NB. expected=. 5
assert 5 -: score 0.800000000000000044 _0.800000000000000044
)

darts_test_09_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_09 =: monad define
Description@.1 ('Just within the middle circle')
Order@.1 (9)

NB. x=. _3.5
NB. y=. 3.5
NB. expected=. 5
assert 5 -: score _3.5 3.5
)

darts_test_10_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_10 =: monad define
Description@.1 ('Just outside the middle circle')
Order@.1 (10)

NB. x=. _3.60000000000000009
NB. y=. _3.60000000000000009
NB. expected=. 1
assert 1 -: score _3.60000000000000009 _3.60000000000000009
)

darts_test_11_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_11 =: monad define
Description@.1 ('Just within the outer circle')
Order@.1 (11)

NB. x=. _7
NB. y=. 7
NB. expected=. 1
assert 1 -: score _7 7
)

darts_test_12_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_12 =: monad define
Description@.1 ('Just outside the outer circle')
Order@.1 (12)

NB. x=. 7.09999999999999964
NB. y=. _7.09999999999999964
NB. expected=. 0
assert 0 -: score 7.09999999999999964 _7.09999999999999964
)

darts_test_13_ignore=: 1 NB. Change this value to 0 to run this test
test_darts_test_13 =: monad define
Description@.1 ('Asymmetric position between the inner and middle circles')
Order@.1 (13)

NB. x=. 0.5
NB. y=. _4
NB. expected=. 5
assert 5 -: score 0.5 _4
)
Loading