New Fetch
This commit is contained in:
28
csharp/sum-of-multiples/README.md
Normal file
28
csharp/sum-of-multiples/README.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Sum Of Multiples
|
||||
|
||||
Given a number, find the sum of all the multiples of particular numbers up to
|
||||
but not including that number.
|
||||
|
||||
If we list all the natural numbers up to but not including 20 that are
|
||||
multiples of either 3 or 5, we get 3, 5, 6 and 9, 10, 12, 15, and 18.
|
||||
|
||||
The sum of these multiples is 78.
|
||||
|
||||
Given a number, find the sum of the multiples of a given set of numbers,
|
||||
up to but not including that number.
|
||||
|
||||
## Hints
|
||||
This exercise requires you to process a collection of data. You can simplify your code by using LINQ (Language Integrated Query).
|
||||
For more information, see [this page](https://docs.microsoft.com/en-us/dotnet/articles/standard/using-linq).
|
||||
|
||||
### Submitting Exercises
|
||||
|
||||
Note that, when trying to submit an exercise, make sure the exercise file that you're submitting is in the `exercism/csharp/<exerciseName>` directory.
|
||||
|
||||
For example, if you're submitting `bob.cs` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/csharp/bob/bob.cs`.
|
||||
## Source
|
||||
|
||||
A variation on Problem 1 at Project Euler [http://projecteuler.net/problem=1](http://projecteuler.net/problem=1)
|
||||
|
||||
## Submitting Incomplete Solutions
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
10
csharp/sum-of-multiples/SumOfMultiples.cs
Normal file
10
csharp/sum-of-multiples/SumOfMultiples.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class SumOfMultiples
|
||||
{
|
||||
public static int To(IEnumerable<int> multiples, int max)
|
||||
{
|
||||
throw new NotImplementedException("You need to implement this function.");
|
||||
}
|
||||
}
|
18
csharp/sum-of-multiples/SumOfMultiples.csproj
Normal file
18
csharp/sum-of-multiples/SumOfMultiples.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Example.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
|
||||
<PackageReference Include="xunit" Version="2.2.0" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
46
csharp/sum-of-multiples/SumOfMultiplesTest.cs
Normal file
46
csharp/sum-of-multiples/SumOfMultiplesTest.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using Xunit;
|
||||
|
||||
public class SumOfMultiplesTest
|
||||
{
|
||||
[Fact]
|
||||
public void Sum_to_1()
|
||||
{
|
||||
Assert.Equal(0, SumOfMultiples.To(new[] { 3, 5 }, 1));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Remove to run test")]
|
||||
public void Sum_to_3()
|
||||
{
|
||||
Assert.Equal(3, SumOfMultiples.To(new[] { 3, 5 }, 4));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Remove to run test")]
|
||||
public void Sum_to_10()
|
||||
{
|
||||
Assert.Equal(23, SumOfMultiples.To(new[] { 3, 5 }, 10));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Remove to run test")]
|
||||
public void Sum_to_100()
|
||||
{
|
||||
Assert.Equal(2318, SumOfMultiples.To(new[] { 3, 5 }, 100));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Remove to run test")]
|
||||
public void Sum_to_1000()
|
||||
{
|
||||
Assert.Equal(233168, SumOfMultiples.To(new[] { 3, 5 }, 1000));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Remove to run test")]
|
||||
public void Sum_to_20()
|
||||
{
|
||||
Assert.Equal(51, SumOfMultiples.To(new [] { 7, 13, 17 }, 20));
|
||||
}
|
||||
|
||||
[Fact(Skip = "Remove to run test")]
|
||||
public void Sum_to_10000()
|
||||
{
|
||||
Assert.Equal(2203160, SumOfMultiples.To(new [] { 43, 47 }, 10000));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user