Some solutions for the julia path
This commit is contained in:
21
julia/darts/.exercism/config.json
Normal file
21
julia/darts/.exercism/config.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"authors": [
|
||||
"vyu"
|
||||
],
|
||||
"contributors": [
|
||||
"cmcaine"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"darts.jl"
|
||||
],
|
||||
"test": [
|
||||
"runtests.jl"
|
||||
],
|
||||
"example": [
|
||||
".meta/example.jl"
|
||||
]
|
||||
},
|
||||
"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
julia/darts/.exercism/metadata.json
Normal file
1
julia/darts/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"julia","exercise":"darts","id":"f274fafe88954ab6bace971d3f6adf19","url":"https://exercism.org/tracks/julia/exercises/darts","handle":"Kimawari","is_requester":true,"auto_approve":false}
|
||||
34
julia/darts/HELP.md
Normal file
34
julia/darts/HELP.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
To run the tests, run this command from within the exercise directory:
|
||||
|
||||
```bash
|
||||
$ julia runtests.jl
|
||||
```
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit darts.jl` command.
|
||||
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||
|
||||
It's possible to submit an incomplete solution which allows you to:
|
||||
|
||||
- See how others have completed the exercise
|
||||
- Request help from a mentor
|
||||
|
||||
## Need to get help?
|
||||
|
||||
If you'd like help solving the exercise, check the following pages:
|
||||
|
||||
- The [Julia track's documentation](https://exercism.org/docs/tracks/julia)
|
||||
- The [Julia track's programming category on the forum](https://forum.exercism.org/c/programming/julia)
|
||||
- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
|
||||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||
|
||||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||
|
||||
To get help if you're having trouble, we recommend that you submit your code and request mentoring :)
|
||||
|
||||
If you don't want to do that for whatever reason, then you can find the wider Julia community channels [here](https://julialang.org/community/).
|
||||
50
julia/darts/README.md
Normal file
50
julia/darts/README.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Darts
|
||||
|
||||
Welcome to Darts on Exercism's Julia Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
|
||||
## 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:
|
||||
|
||||

|
||||
|
||||
- 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
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @vyu
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @cmcaine
|
||||
|
||||
### Based on
|
||||
|
||||
Inspired by an exercise created by a professor Della Paolera in Argentina
|
||||
12
julia/darts/darts.jl
Normal file
12
julia/darts/darts.jl
Normal file
@@ -0,0 +1,12 @@
|
||||
function score(x, y)
|
||||
dist = sqrt(x^2 + y^2)
|
||||
if dist <= 1
|
||||
return 10
|
||||
elseif dist <= 5
|
||||
return 5
|
||||
elseif dist <= 10
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
end
|
||||
end
|
||||
57
julia/darts/runtests.jl
Normal file
57
julia/darts/runtests.jl
Normal file
@@ -0,0 +1,57 @@
|
||||
using Test
|
||||
|
||||
include("darts.jl")
|
||||
|
||||
@testset verbose = true "tests" begin
|
||||
@testset "Missed target" begin
|
||||
@test score(-9, 9) == 0
|
||||
end
|
||||
|
||||
@testset "On the outer circle" begin
|
||||
@test score(0, 10) == 1
|
||||
end
|
||||
|
||||
@testset "On the middle circle" begin
|
||||
@test score(-5, 0) == 5
|
||||
end
|
||||
|
||||
@testset "On the inner circle" begin
|
||||
@test score(0, -1) == 10
|
||||
end
|
||||
|
||||
@testset "Exactly on centre" begin
|
||||
@test score(0, 0) == 10
|
||||
end
|
||||
|
||||
@testset "Near the centre" begin
|
||||
@test score(-0.1, -0.1) == 10
|
||||
end
|
||||
|
||||
@testset "Just within the inner circle" begin
|
||||
@test score(0.7, 0.7) == 10
|
||||
end
|
||||
|
||||
@testset "Just outside the inner circle" begin
|
||||
@test score(0.8, -0.8) == 5
|
||||
end
|
||||
|
||||
@testset "Just within the middle circle" begin
|
||||
@test score(-3.5, 3.5) == 5
|
||||
end
|
||||
|
||||
@testset "Just outside the middle circle" begin
|
||||
@test score(-3.6, -3.6) == 1
|
||||
end
|
||||
|
||||
@testset "Just within the outer circle" begin
|
||||
@test score(-7.0, 7.0) == 1
|
||||
end
|
||||
|
||||
@testset "Just outside the outer circle" begin
|
||||
@test score(7.1, -7.1) == 0
|
||||
end
|
||||
|
||||
@testset "Asymmetric position between the inner and middle circles" begin
|
||||
@test score(0.5, -4) == 5
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user