Update it all, VisualStudio Changes

This commit is contained in:
2016-08-23 12:33:06 -05:00
parent 2a0c6f9e45
commit b8814259b5
136 changed files with 180080 additions and 66 deletions

View File

@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FEF69435-D885-45DD-A446-04FD3BD3F593}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Exercism</RootNamespace>
<AssemblyName>Exercism.csharp</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="anagram\Anagram.cs" />
<Compile Include="anagram\AnagramTest.cs" />
<Compile Include="bob\Bob.cs" />
<Compile Include="bob\BobTest.cs" />
<Compile Include="etl\ETL.cs" />
<Compile Include="etl\ETLTest.cs" />
<Compile Include="grade-school\GradeSchoolTest.cs" />
<Compile Include="hamming\Hamming.cs" />
<Compile Include="hamming\HammingTest.cs" />
<Compile Include="leap\leap.cs" />
<Compile Include="leap\LeapTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="word-count\Phrase.cs" />
<Compile Include="word-count\WordCountTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="anagram\README.md" />
<None Include="bob\README.md" />
<None Include="etl\README.md" />
<None Include="grade-school\README.md" />
<None Include="hamming\README.md" />
<None Include="leap\README.md" />
<None Include="packages.config" />
<None Include="word-count\README.md" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectView>ShowAllFiles</ProjectView>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Exercism")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Exercism")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6ffaaf65-a0b4-4ff5-b2eb-e275df05cc6e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

40
csharp/anagram/Anagram.cs Normal file
View File

@@ -0,0 +1,40 @@
using System.Collections.Generic;
internal class Anagram {
private string v;
// Anagram is initialized with a string to test other strings against
public Anagram(string v) {
this.v = v.ToLower();
}
// Match takes an array of strings and returns an array that contains
// All anagrams of this.v
public string[] Match(string[] inp) {
List<string> ret = new List<string>();
foreach(string val in inp) {
if(this.v.Length != val.Length) {
continue;
}
string valTest = val.ToLower();
bool isAnagram = true;
if(this.v == valTest) {
continue;
}
for(int i = 0; i < this.v.Length; i++) {
int idx = valTest.IndexOf(this.v[i]);
if(idx == -1) {
isAnagram = false;
}
if(!isAnagram) {
break;
}
valTest = valTest.Substring(0, idx)+valTest.Substring(idx+1);
}
if(isAnagram) {
ret.Add(val);
}
}
return ret.ToArray();
}
}

View File

@@ -0,0 +1,96 @@
using NUnit.Framework;
[TestFixture]
public class AnagramTest
{
[Ignore]
[Test]
public void No_matches()
{
var detector = new Anagram("diaper");
var words = new[] { "hello", "world", "zombies", "pants" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Detect_simple_anagram()
{
var detector = new Anagram("ant");
var words = new[] { "tan", "stand", "at" };
var results = new[] { "tan" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Detect_multiple_anagrams()
{
var detector = new Anagram("master");
var words = new[] { "stream", "pigeon", "maters" };
var results = new[] { "maters", "stream" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Does_not_confuse_different_duplicates()
{
var detector = new Anagram("galea");
var words = new[] { "eagle" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Identical_word_is_not_anagram()
{
var detector = new Anagram("corn");
var words = new[] { "corn", "dark", "Corn", "rank", "CORN", "cron", "park" };
var results = new[] { "cron" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Eliminate_anagrams_with_same_checksum()
{
var detector = new Anagram("mass");
var words = new[] { "last" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Eliminate_anagram_subsets()
{
var detector = new Anagram("good");
var words = new[] { "dog", "goody" };
var results = new string[0];
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Detect_anagrams()
{
var detector = new Anagram("allergy");
var words = new[] { "gallery", "ballerina", "regally", "clergy", "largely", "leading" };
var results = new[] { "gallery", "largely", "regally" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
[Ignore]
[Test]
public void Anagrams_are_case_insensitive()
{
var detector = new Anagram("Orchestra");
var words = new[] { "cashregister", "Carthorse", "radishes" };
var results = new[] { "Carthorse" };
Assert.That(detector.Match(words), Is.EquivalentTo(results));
}
}

21
csharp/anagram/README.md Normal file
View File

@@ -0,0 +1,21 @@
# Anagram
Write a program that, given a word and a list of possible anagrams, selects the correct sublist.
Given `"listen"` and a list of candidates like `"enlists" "google"
"inlets" "banana"` the program should return a list containing
`"inlets"`.
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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
Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

15
csharp/bob/Bob.cs Normal file
View File

@@ -0,0 +1,15 @@
internal class Bob {
public static string Hey(string inp) {
inp = inp.Trim();
if(inp == "") {
return "Fine. Be that way!";
}
if(inp == inp.ToUpper() && inp != inp.ToLower()) {
return "Whoa, chill out!";
}
if(inp[inp.Length-1] == '?') {
return "Sure.";
}
return "Whatever.";
}
}

131
csharp/bob/BobTest.cs Normal file
View File

@@ -0,0 +1,131 @@
using NUnit.Framework;
[TestFixture]
public class BobTest
{
[Ignore]
[Test]
public void Stating_something ()
{
Assert.That(Bob.Hey("Tom-ay-to, tom-aaaah-to."), Is.EqualTo("Whatever."));
}
[Ignore]
[Test]
public void Shouting ()
{
Assert.That(Bob.Hey("WATCH OUT!"), Is.EqualTo("Whoa, chill out!"));
}
[Ignore]
[Test]
public void Asking_a_question ()
{
Assert.That(Bob.Hey("Does this cryogenic chamber make me look fat?"), Is.EqualTo("Sure."));
}
[Ignore]
[Test]
public void Asking_a_question_with_a_trailing_space()
{
Assert.That(Bob.Hey("Do I like my spacebar too much? "), Is.EqualTo("Sure."));
}
[Ignore]
[Test]
public void Asking_a_numeric_question ()
{
Assert.That(Bob.Hey("You are, what, like 15?"), Is.EqualTo("Sure."));
}
[Ignore]
[Test]
public void Talking_forcefully ()
{
Assert.That(Bob.Hey("Let's go make out behind the gym!"), Is.EqualTo("Whatever."));
}
[Ignore]
[Test]
public void Using_acronyms_in_regular_search ()
{
Assert.That(Bob.Hey("It's OK if you don't want to go to the DMV."), Is.EqualTo("Whatever."));
}
[Ignore]
[Test]
public void Forceful_questions ()
{
Assert.That(Bob.Hey("WHAT THE HELL WERE YOU THINKING?"), Is.EqualTo("Whoa, chill out!"));
}
[Ignore]
[Test]
public void Shouting_numbers ()
{
Assert.That(Bob.Hey("1, 2, 3 GO!"), Is.EqualTo("Whoa, chill out!"));
}
[Ignore]
[Test]
public void Only_numbers ()
{
Assert.That(Bob.Hey("1, 2, 3"), Is.EqualTo("Whatever."));
}
[Ignore]
[Test]
public void Question_with_only_numbers ()
{
Assert.That(Bob.Hey("4?"), Is.EqualTo("Sure."));
}
[Ignore]
[Test]
public void Shouting_with_special_characters ()
{
Assert.That(Bob.Hey("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"), Is.EqualTo("Whoa, chill out!"));
}
[Ignore]
[Test]
public void Shouting_with_no_exclamation_mark ()
{
Assert.That(Bob.Hey("I HATE YOU"), Is.EqualTo("Whoa, chill out!"));
}
[Ignore]
[Test]
public void Statement_containing_question_mark ()
{
Assert.That(Bob.Hey("Ending with ? means a question."), Is.EqualTo("Whatever."));
}
[Ignore]
[Test]
public void Prattling_on ()
{
Assert.That(Bob.Hey("Wait! Hang on. Are you going to be OK?"), Is.EqualTo("Sure."));
}
[Ignore]
[Test]
public void Silence ()
{
Assert.That(Bob.Hey(""), Is.EqualTo("Fine. Be that way!"));
}
[Ignore]
[Test]
public void Prolonged_silence ()
{
Assert.That(Bob.Hey(" "), Is.EqualTo("Fine. Be that way!"));
}
[Ignore]
[Test]
public void Multiple_line_question ()
{
Assert.That(Bob.Hey("Does this cryogenic chamber make me look fat?\nno"), Is.EqualTo("Whatever."));
}
}

44
csharp/bob/README.md Normal file
View File

@@ -0,0 +1,44 @@
# Bob
Bob is a lackadaisical teenager. In conversation, his responses are very limited.
Bob answers 'Sure.' if you ask him a question.
He answers 'Whoa, chill out!' if you yell at him.
He says 'Fine. Be that way!' if you address him without actually saying
anything.
He answers 'Whatever.' to anything else.
## Instructions
Run the test file, and fix each of the errors in turn. When you get the
first test to pass, go to the first pending or skipped test, and make
that pass as well. When all of the tests are passing, feel free to
submit.
Remember that passing code is just the first step. The goal is to work
towards a solution that is as readable and expressive as you can make
it.
Please make your solution as general as possible. Good code doesn't just
pass the test suite, it works with any input that fits the
specification.
Have fun!
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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
Inspired by the 'Deaf Grandma' exercise in Chris Pine's Learn to Program tutorial. [http://pine.fm/LearnToProgram/?Chapter=06](http://pine.fm/LearnToProgram/?Chapter=06)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@@ -1 +0,0 @@
leap

18
csharp/etl/ETL.cs Normal file
View File

@@ -0,0 +1,18 @@
using System.IO;
using System;
using System.Collections.Generic;
class ETL {
public static Dictionary<string, int> Transform(Dictionary<int, IList<string>> inp) {
Dictionary<string, int> ret = new Dictionary<string, int>();
foreach(KeyValuePair<int, IList<string>> entry in inp) {
foreach(string val in entry.Value) {
string v = val.ToLower();
if(!ret.ContainsKey(v)) {
ret.Add(v, entry.Key);
}
}
}
return ret;
}
}

56
csharp/etl/ETLTest.cs Normal file
View File

@@ -0,0 +1,56 @@
using System.Collections.Generic;
using NUnit.Framework;
[TestFixture]
public class ETLTest
{
[Ignore]
[Test]
public void Transforms_one_value()
{
var old = new Dictionary<int, IList<string>> { { 1, new List<string> { "A" } } };
var expected = new Dictionary<string, int> { { "a", 1 } };
Assert.That(ETL.Transform(old), Is.EqualTo(expected));
}
[Ignore]
[Test]
public void Transforms_multiple_values()
{
var old = new Dictionary<int, IList<string>> { { 1, new List<string> { "A", "E", "I", "O", "U" } } };
var expected = new Dictionary<string, int> { { "a", 1 }, { "e", 1 }, { "i", 1 }, { "o", 1 }, { "u", 1 } };
Assert.That(ETL.Transform(old), Is.EqualTo(expected));
}
[Ignore]
[Test]
public void Transforms_multiple_keys()
{
var old = new Dictionary<int, IList<string>> { { 1, new List<string> { "A", "E" } }, { 2, new List<string> { "D", "G" } } };
var expected = new Dictionary<string, int> { { "a", 1 }, { "e", 1 }, { "d", 2 }, { "g", 2 } };
Assert.That(ETL.Transform(old), Is.EqualTo(expected));
}
[Ignore]
[Test]
public void Transforms_a_full_dataset()
{
var old = new Dictionary<int, IList<string>>
{
{ 1, new List<string> { "A", "E", "I", "O", "U", "L", "N", "R", "S", "T" } },
{ 2, new List<string> { "D", "G" } },
{ 3, new List<string> { "B", "C", "M", "P" } },
{ 4, new List<string> { "F", "H", "V", "W", "Y" } },
{ 5, new List<string> { "K" } },
{ 8, new List<string> { "J", "X" } },
{ 10, new List<string> { "Q", "Z" } },
};
var expected = new Dictionary<string, int>
{
{ "a", 1 }, { "b", 3 }, { "c", 3 }, { "d", 2 }, { "e", 1 }, { "f", 4 }, { "g", 2 }, { "h", 4 }, { "i", 1 },
{ "j", 8 }, { "k", 5 }, { "l", 1 }, { "m", 3 }, { "n", 1 }, { "o", 1 }, { "p", 3 }, { "q", 10 }, { "r", 1 },
{ "s", 1 }, { "t", 1 }, { "u", 1 }, { "v", 4 }, { "w", 4 }, { "x", 8 }, { "y", 4 }, { "z", 10 }
};
Assert.That(ETL.Transform(old), Is.EqualTo(expected));
}
}

59
csharp/etl/README.md Normal file
View File

@@ -0,0 +1,59 @@
# Etl
We are going to do the `Transform` step of an Extract-Transform-Load.
### ETL
Extract-Transform-Load (ETL) is a fancy way of saying, "We have some crufty, legacy data over in this system, and now we need it in this shiny new system over here, so
we're going to migrate this."
(Typically, this is followed by, "We're only going to need to run this
once." That's then typically followed by much forehead slapping and
moaning about how stupid we could possibly be.)
### The goal
We're going to extract some scrabble scores from a legacy system.
The old system stored a list of letters per score:
- 1 point: "A", "E", "I", "O", "U", "L", "N", "R", "S", "T",
- 2 points: "D", "G",
- 3 points: "B", "C", "M", "P",
- 4 points: "F", "H", "V", "W", "Y",
- 5 points: "K",
- 8 points: "J", "X",
- 10 points: "Q", "Z",
The shiny new scrabble system instead stores the score per letter, which
makes it much faster and easier to calculate the score for a word. It
also stores the letters in lower-case regardless of the case of the
input letters:
- "a" is worth 1 point.
- "b" is worth 3 points.
- "c" is worth 3 points.
- "d" is worth 2 points.
- Etc.
Your mission, should you choose to accept it, is to write a program that
transforms the legacy data format to the shiny new format.
### Notes
A final note about scoring, Scrabble is played around the world in a
variety of languages, each with its own unique scoring table. For
example, an "E" is scored at 2 in the Māori-language version of the
game while being scored at 4 in the Hawaiian-language version.
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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
The Jumpstart Lab team [http://jumpstartlab.com](http://jumpstartlab.com)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@@ -0,0 +1,81 @@
using System.Collections.Generic;
using NUnit.Framework;
[TestFixture]
public class GradeSchoolTest
{
private School school;
[SetUp]
public void Setup()
{
school = new School();
}
[Test]
public void New_school_has_an_empty_roster()
{
Assert.That(school.Roster, Has.Count.EqualTo(0));
}
[Ignore("Remove to run test")]
[Test]
public void Adding_a_student_adds_them_to_the_roster_for_the_given_grade()
{
school.Add("Aimee", 2);
var expected = new List<string> { "Aimee" };
Assert.That(school.Roster[2], Is.EqualTo(expected));
}
[Ignore("Remove to run test")]
[Test]
public void Adding_more_students_to_the_same_grade_adds_them_to_the_roster()
{
school.Add("Blair", 2);
school.Add("James", 2);
school.Add("Paul", 2);
var expected = new List<string> { "Blair", "James", "Paul" };
Assert.That(school.Roster[2], Is.EqualTo(expected));
}
[Ignore("Remove to run test")]
[Test]
public void Adding_students_to_different_grades_adds_them_to_the_roster()
{
school.Add("Chelsea", 3);
school.Add("Logan", 7);
Assert.That(school.Roster[3], Is.EqualTo(new List<string> { "Chelsea" }));
Assert.That(school.Roster[7], Is.EqualTo(new List<string> { "Logan" }));
}
[Ignore("Remove to run test")]
[Test]
public void Grade_returns_the_students_in_that_grade_in_alphabetical_order()
{
school.Add("Franklin", 5);
school.Add("Bradley", 5);
school.Add("Jeff", 1);
var expected = new List<string> { "Bradley", "Franklin" };
Assert.That(school.Grade(5), Is.EqualTo(expected));
}
[Ignore("Remove to run test")]
[Test]
public void Grade_returns_an_empty_list_if_there_are_no_students_in_that_grade()
{
Assert.That(school.Grade(1), Is.EqualTo(new List<string>()));
}
[Ignore("Remove to run test")]
[Test]
public void Student_names_in_each_grade_in_roster_are_sorted()
{
school.Add("Jennifer", 4);
school.Add("Kareem", 6);
school.Add("Christopher", 4);
school.Add("Kyle", 3);
Assert.That(school.Roster[3], Is.EqualTo(new List<string> { "Kyle" }));
Assert.That(school.Roster[4], Is.EqualTo(new List<string> { "Christopher", "Jennifer" }));
Assert.That(school.Roster[6], Is.EqualTo(new List<string> { "Kareem" }));
}
}

View File

@@ -0,0 +1,49 @@
# Grade School
Write a small archiving program that stores students' names along with the grade that they are in.
In the end, you should be able to:
- Add a student's name to the roster for a grade
- "Add Jim to grade 2."
- "OK."
- Get a list of all students enrolled in a grade
- "Which students are in grade 2?"
- "We've only got Jim just now."
- Get a sorted list of all students in all grades. Grades should sort
as 1, 2, 3, etc., and students within a grade should be sorted
alphabetically by name.
- "Who all is enrolled in school right now?"
- "Grade 1: Anna, Barb, and Charlie. Grade 2: Alex, Peter, and Zoe.
Grade 3…"
Note that all our students only have one name. (It's a small town, what
do you want?)
## For bonus points
Did you get the tests passing and the code clean? If you want to, these
are some additional things you could try:
- If you're working in a language with mutable data structures and your
implementation allows outside code to mutate the school's internal DB
directly, see if you can prevent this. Feel free to introduce additional
tests.
Then please share your thoughts in a comment on the submission. Did this
experiment make the code better? Worse? Did you learn anything from it?
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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 pairing session with Phil Battos at gSchool [http://gschool.it](http://gschool.it)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

14
csharp/hamming/Hamming.cs Normal file
View File

@@ -0,0 +1,14 @@
internal class Hamming {
public static int Compute(string strand1, string strand2) {
int ret = 0;
if(strand1.Length != strand2.Length) {
throw new System.ArgumentException("Strands must be same length");
}
for(int i = 0; i < strand1.Length; i++) {
if(strand1[i] != strand2[i]) {
ret++;
}
}
return ret;
}
}

View File

@@ -0,0 +1,47 @@
using NUnit.Framework;
[TestFixture]
public class HammingTest
{
[Ignore]
[Test]
public void No_difference_between_empty_strands()
{
Assert.That(Hamming.Compute("",""), Is.EqualTo(0));
}
[Ignore]
[Test]
public void No_difference_between_identical_strands()
{
Assert.That(Hamming.Compute("GGACTGA","GGACTGA"), Is.EqualTo(0));
}
[Ignore]
[Test]
public void Complete_hamming_distance_in_small_strand()
{
Assert.That(Hamming.Compute("ACT","GGA"), Is.EqualTo(3));
}
[Ignore]
[Test]
public void Hamming_distance_is_off_by_one_strand()
{
Assert.That(Hamming.Compute("GGACGGATTCTG","AGGACGGATTCT"), Is.EqualTo(9));
}
[Ignore]
[Test]
public void Smalling_hamming_distance_in_middle_somewhere()
{
Assert.That(Hamming.Compute("GGACG","GGTCG"), Is.EqualTo(1));
}
[Ignore]
[Test]
public void Larger_distance()
{
Assert.That(Hamming.Compute("ACCAGGG","ACTATGG"), Is.EqualTo(2));
}
}

50
csharp/hamming/README.md Normal file
View File

@@ -0,0 +1,50 @@
# Hamming
Write a program that can calculate the Hamming difference between two DNA strands.
A mutation is simply a mistake that occurs during the creation or
copying of a nucleic acid, in particular DNA. Because nucleic acids are
vital to cellular functions, mutations tend to cause a ripple effect
throughout the cell. Although mutations are technically mistakes, a very
rare mutation may equip the cell with a beneficial attribute. In fact,
the macro effects of evolution are attributable by the accumulated
result of beneficial microscopic mutations over many generations.
The simplest and most common type of nucleic acid mutation is a point
mutation, which replaces one base with another at a single nucleotide.
By counting the number of differences between two homologous DNA strands
taken from different genomes with a common ancestor, we get a measure of
the minimum number of point mutations that could have occurred on the
evolutionary path between the two strands.
This is called the 'Hamming distance'.
It is found by comparing two DNA strands and counting how many of the
nucleotides are different from their equivalent in the other string.
GAGCCTACTAACGGGAT
CATCGTAATGACGGCCT
^ ^ ^ ^ ^ ^^
The Hamming distance between these two DNA strands is 7.
# Implementation notes
The Hamming distance is only defined for sequences of equal length. This means
that based on the definition, each language could deal with getting sequences
of equal length differently.
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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
The Calculating Point Mutations problem at Rosalind [http://rosalind.info/problems/hamm/](http://rosalind.info/problems/hamm/)
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@@ -1,32 +1,31 @@
using NUnit.Framework;
[TestFixture]
public class LeapTest
{
[Test]
public void Valid_leap_year()
{
Assert.That(Year.IsLeap(1996), Is.True);
}
[Ignore]
[Test]
public void Invalid_leap_year()
{
Assert.That(Year.IsLeap(1997), Is.False);
}
[Ignore]
[Test]
public void Turn_of_the_20th_century_is_not_a_leap_year()
{
Assert.That(Year.IsLeap(1900), Is.False);
}
[Ignore]
[Test]
public void Turn_of_the_25th_century_is_a_leap_year()
{
Assert.That(Year.IsLeap(2400), Is.True);
}
}
using NUnit.Framework;
[TestFixture]
public class LeapTest
{
[Ignore]
[Test]
public void Valid_leap_year()
{
Assert.That(Year.IsLeap(1996), Is.True);
}
[Ignore]
[Test]
public void Invalid_leap_year()
{
Assert.That(Year.IsLeap(1997), Is.False);
}
[Ignore("Remove to run test")]
public void Turn_of_the_20th_century_is_not_a_leap_year()
{
Assert.That(Year.IsLeap(1900), Is.False);
}
[Ignore("Remove to run test")]
public void Turn_of_the_25th_century_is_a_leap_year()
{
Assert.That(Year.IsLeap(2400), Is.True);
}
}

View File

@@ -1,33 +1,37 @@
# Leap
Write a program that will take a year and report if it is a leap year.
The tricky thing here is that a leap year occurs:
```plain
on every year that is evenly divisible by 4
except every year that is evenly divisible by 100
unless the year is also evenly divisible by 400
```
For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap
year, but 2000 is.
If your language provides a method in the standard library that does
this look-up, pretend it doesn't exist and implement it yourself.
## Notes
For a delightful, four minute explanation of the whole leap year
phenomenon, go watch [this youtube video][video].
[video]: http://www.youtube.com/watch?v=xX96xng7sAE
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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
JavaRanch Cattle Drive, exercise 3 [view source](http://www.javaranch.com/leap.jsp)
# Leap
Write a program that will take a year and report if it is a leap year.
The tricky thing here is that a leap year in the Gregorian calendar occurs:
```plain
on every year that is evenly divisible by 4
except every year that is evenly divisible by 100
unless the year is also evenly divisible by 400
```
For example, 1997 is not a leap year, but 1996 is. 1900 is not a leap
year, but 2000 is.
If your language provides a method in the standard library that does
this look-up, pretend it doesn't exist and implement it yourself.
## Notes
Though our exercise adopts some very simple rules, there is more to
learn!
For a delightful, four minute explanation of the whole leap year
phenomenon, go watch [this youtube video][video].
[video]: http://www.youtube.com/watch?v=xX96xng7sAE
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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
JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp)

13
csharp/leap/leap.cs Normal file
View File

@@ -0,0 +1,13 @@
class Year {
public static bool IsLeap(int i) {
if(i % 4 == 0) {
if(i % 100 == 0) {
if (i % 400 != 0) {
return false;
}
}
return true;
}
return false;
}
}

View File

@@ -0,0 +1,7 @@
C:\Users\brbuller\Development\exercism\csharp\obj\Debug\Exercism.csharp.csprojResolveAssemblyReference.cache
C:\Users\brbuller\Development\exercism\csharp\bin\Debug\Exercism.csharp.dll
C:\Users\brbuller\Development\exercism\csharp\bin\Debug\Exercism.csharp.pdb
C:\Users\brbuller\Development\exercism\csharp\bin\Debug\nunit.framework.dll
C:\Users\brbuller\Development\exercism\csharp\bin\Debug\nunit.framework.xml
C:\Users\brbuller\Development\exercism\csharp\obj\Debug\Exercism.csharp.dll
C:\Users\brbuller\Development\exercism\csharp\obj\Debug\Exercism.csharp.pdb

Binary file not shown.

Binary file not shown.

4
csharp/packages.config Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.6.3" targetFramework="net45" />
</packages>

View File

@@ -0,0 +1,27 @@
using System.Text.RegularExpressions;
using System.Collections.Generic;
class Phrase {
public static Dictionary<string,int> WordCount(string phrase) {
Dictionary<string,int> ret = new Dictionary<string,int>();
Regex rgx = new Regex("[^a-zA-Z0-9 ,']");
phrase = rgx.Replace(phrase, "");
string[] words = Regex.Split(phrase, @"[\s,]");
char[] trimChars = new char[2];
trimChars[0] = ' ';
trimChars[1] = '\'';
foreach(string wrd in words) {
string normWrd = wrd.ToLower().Trim(trimChars);
if(normWrd != "") {
int num = 0;
if(ret.ContainsKey(normWrd)) {
ret.TryGetValue(normWrd, out num);
ret.Remove(normWrd);
}
num++;
ret.Add(normWrd, num);
}
}
return ret;
}
}

View File

@@ -0,0 +1,27 @@
# Word Count
Write a program that given a phrase can count the occurrences of each word in that phrase.
For example for the input `"olly olly in come free"`
```plain
olly: 2
in: 1
come: 1
free: 1
```
### Submitting Exercises
Note that, when trying to submit an exercise, make sure you're exercise file 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
This is a classic toy problem, but we were reminded of it by seeing it in the Go Tour.
## Submitting Incomplete Problems
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

View File

@@ -0,0 +1,157 @@
using System.Collections.Generic;
using NUnit.Framework;
[TestFixture]
public class WordCountTest
{
[Ignore]
[Test]
public void Count_one_word()
{
var counts = new Dictionary<string,int> {
{ "word", 1 }
};
Assert.That(Phrase.WordCount("word"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void Count_one_of_each()
{
var counts = new Dictionary<string,int> {
{ "one", 1 },
{ "of", 1 },
{ "each", 1 }
};
Assert.That(Phrase.WordCount("one of each"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void Count_multiple_occurrences()
{
var counts = new Dictionary<string,int> {
{ "one", 1 },
{ "fish", 4 },
{ "two", 1 },
{ "red", 1 },
{ "blue", 1 },
};
Assert.That(Phrase.WordCount("one fish two fish red fish blue fish"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void Count_everything_just_once()
{
var counts = new Dictionary<string,int> {
{ "all", 2 },
{ "the", 2 },
{ "kings", 2 },
{ "horses", 1 },
{ "and", 1 },
{ "men", 1 },
};
Assert.That(Phrase.WordCount("all the kings horses and all the kings men"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void Ignore_punctuation()
{
var counts = new Dictionary<string,int> {
{ "car", 1 },
{ "carpet", 1 },
{ "as", 1 },
{ "java", 1 },
{ "javascript", 1 },
};
Assert.That(Phrase.WordCount("car : carpet as java : javascript!!&@$%^&"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void Handles_cramped_list()
{
var counts = new Dictionary<string,int> {
{ "one", 1 },
{ "two", 1 },
{ "three", 1 },
};
Assert.That(Phrase.WordCount("one,two,three"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void Include_numbers()
{
var counts = new Dictionary<string,int> {
{ "testing", 2 },
{ "1", 1 },
{ "2", 1 },
};
Assert.That(Phrase.WordCount("testing, 1, 2 testing"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void Normalize_case()
{
var counts = new Dictionary<string,int> {
{ "go", 3 },
};
Assert.That(Phrase.WordCount("go Go GO"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void With_apostrophes()
{
var counts = new Dictionary<string,int> {
{ "first", 1 },
{ "don't", 2 },
{ "laugh", 1 },
{ "then", 1 },
{ "cry", 1 },
};
Assert.That(Phrase.WordCount("First: don't laugh. Then: don't cry."), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void With_free_standing_apostrophes()
{
var counts = new Dictionary<string, int> {
{ "go", 3 },
};
Assert.That(Phrase.WordCount("go ' Go '' GO"), Is.EqualTo(counts));
}
[Ignore]
[Test]
public void With_apostrophes_as_quotes()
{
var counts = new Dictionary<string, int> {
{ "she", 1 },
{ "said", 1 },
{ "let's", 1 },
{ "meet", 1 },
{ "at", 1 },
{ "twelve", 1 },
{ "o'clock", 1 },
};
Assert.That(Phrase.WordCount("She said, 'let's meet at twelve o'clock'"), Is.EqualTo(counts));
}
}