Skip to content

Commit aaabc8d

Browse files
bmeverettErikSchierboom
authored andcommitted
Add Darts Exercise (#712)
* add darts exercise * make darts class static * update Darts project file * remove empty line * add README and update darts UUID * update README with additional instructions * update config.json with proper values * remove space from config.json uuid
1 parent a2d5985 commit aaabc8d

8 files changed

Lines changed: 246 additions & 483 deletions

File tree

config.json

Lines changed: 123 additions & 482 deletions
Large diffs are not rendered by default.

exercises/Exercises.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Yacht", "yacht\Yacht.csproj
230230
EndProject
231231
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RationalNumbers", "rational-numbers\RationalNumbers.csproj", "{0CBB430D-BF64-436F-93BE-8E8088DBCBFE}"
232232
EndProject
233-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AffineCipher", "affine-cipher\AffineCipher.csproj", "{758DDF02-FFE7-4A4A-BD7C-0B189F3257C9}"
233+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AffineCipher", "affine-cipher\AffineCipher.csproj", "{758DDF02-FFE7-4A4A-BD7C-0B189F3257C9}"
234234
EndProject
235235
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RestApi", "rest-api\RestApi.csproj", "{DFF04F1E-2963-4A88-AF92-D14AD48617F2}"
236236
EndProject
237+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Darts", "darts\Darts.csproj", "{202E2755-AB2F-4EA5-94D0-574487079CFF}"
238+
EndProject
237239
Global
238240
GlobalSection(SolutionConfigurationPlatforms) = preSolution
239241
Debug|Any CPU = Debug|Any CPU
@@ -704,6 +706,10 @@ Global
704706
{DFF04F1E-2963-4A88-AF92-D14AD48617F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
705707
{DFF04F1E-2963-4A88-AF92-D14AD48617F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
706708
{DFF04F1E-2963-4A88-AF92-D14AD48617F2}.Release|Any CPU.Build.0 = Release|Any CPU
709+
{202E2755-AB2F-4EA5-94D0-574487079CFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
710+
{202E2755-AB2F-4EA5-94D0-574487079CFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
711+
{202E2755-AB2F-4EA5-94D0-574487079CFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
712+
{202E2755-AB2F-4EA5-94D0-574487079CFF}.Release|Any CPU.Build.0 = Release|Any CPU
707713
EndGlobalSection
708714
GlobalSection(SolutionProperties) = preSolution
709715
HideSolutionNode = FALSE

exercises/darts/Darts.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
public static class Darts
4+
{
5+
public static int Score(double x, double y)
6+
{
7+
throw new NotImplementedException("You need to implement this function");
8+
}
9+
}

exercises/darts/Darts.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<Compile Remove="Example.cs" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
13+
<PackageReference Include="xunit" Version="2.4.0" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
15+
</ItemGroup>
16+
17+
</Project>

exercises/darts/DartsTest.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// This file was auto-generated based on version 1.0.0 of the canonical data.
2+
3+
using Xunit;
4+
5+
public class DartsTest
6+
{
7+
[Fact]
8+
public void A_dart_lands_outside_the_target()
9+
{
10+
Assert.Equal(0, Darts.Score(15.3, 13.2));
11+
}
12+
13+
[Fact(Skip = "Remove to run test")]
14+
public void A_dart_lands_just_in_the_border_of_the_target()
15+
{
16+
Assert.Equal(1, Darts.Score(10, 0));
17+
}
18+
19+
[Fact(Skip = "Remove to run test")]
20+
public void A_dart_lands_in_the_middle_circle()
21+
{
22+
Assert.Equal(5, Darts.Score(3, 3.7));
23+
}
24+
25+
[Fact(Skip = "Remove to run test")]
26+
public void A_dart_lands_right_in_the_border_between_outside_and_middle_circles()
27+
{
28+
Assert.Equal(5, Darts.Score(0, 5));
29+
}
30+
31+
[Fact(Skip = "Remove to run test")]
32+
public void A_dart_lands_in_the_inner_circle()
33+
{
34+
Assert.Equal(10, Darts.Score(0, 0));
35+
}
36+
}

exercises/darts/Example.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
3+
public static class Darts
4+
{
5+
public static int Score(double x, double y)
6+
{
7+
var diff = Math.Pow(x, 2) + Math.Pow(y, 2);
8+
if (diff > 100) // outside the radius 10 squared
9+
return 0;
10+
if (diff <= 100 && diff > 25) // outer circle radius of 10 squared
11+
return 1;
12+
if (diff <= 25 && diff > 1) // middle circle radius of 5 squared
13+
return 5;
14+
if (diff <= 1) // in circle radius of 1 squared
15+
return 10;
16+
17+
return 0;
18+
}
19+
}

exercises/darts/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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.
16+
17+
## Running the tests
18+
19+
To run the tests, run the command `dotnet test` from within the exercise directory.
20+
21+
## Further information
22+
23+
For more detailed information about the C# track, including how to get help if
24+
you're having trouble, please visit the exercism.io [C# language page](http://exercism.io/languages/csharp/resources).
25+
26+
## Submitting Incomplete Solutions
27+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Exercism.CSharp.Exercises;
2+
3+
namespace Exercism.CSharp.Exercises.Generators
4+
{
5+
public class Darts : GeneratorExercise
6+
{
7+
}
8+
}

0 commit comments

Comments
 (0)