Browse Source

init

master
Ben Harris 4 years ago
commit
105e38b22f
  1. 17
      crystal/.gitignore
  2. 78
      crystal/hello-world/README.md
  3. 8
      crystal/hello-world/spec/hello_world_spec.cr
  4. 2
      crystal/hello-world/src/hello_world.cr
  5. 33
      csharp/.gitignore
  6. 10
      csharp/accumulate/Accumulate.cs
  7. 17
      csharp/accumulate/Accumulate.csproj
  8. 63
      csharp/accumulate/AccumulateTest.cs
  9. 37
      csharp/accumulate/README.md
  10. 20
      csharp/bob/Bob.cs
  11. 17
      csharp/bob/Bob.csproj
  12. 156
      csharp/bob/BobTest.cs
  13. 22
      csharp/bob/README.md
  14. 20
      csharp/grade-school/GradeSchool.cs
  15. 17
      csharp/grade-school/GradeSchool.csproj
  16. 85
      csharp/grade-school/GradeSchoolTest.cs
  17. 43
      csharp/grade-school/README.md
  18. 6
      csharp/hello-world/HelloWorld.cs
  19. 17
      csharp/hello-world/HelloWorld.csproj
  20. 12
      csharp/hello-world/HelloWorldTest.cs
  21. 23
      csharp/hello-world/README.md
  22. 9
      csharp/leap/Leap.cs
  23. 17
      csharp/leap/Leap.csproj
  24. 30
      csharp/leap/LeapTest.cs
  25. 35
      csharp/leap/README.md
  26. 31
      csharp/nucleotide-count/NucleotideCount.cs
  27. 17
      csharp/nucleotide-count/NucleotideCount.csproj
  28. 69
      csharp/nucleotide-count/NucleotideCountTest.cs
  29. 25
      csharp/nucleotide-count/README.md
  30. 26
      csharp/raindrops/README.md
  31. 20
      csharp/raindrops/Raindrops.cs
  32. 17
      csharp/raindrops/Raindrops.csproj
  33. 114
      csharp/raindrops/RaindropsTest.cs
  34. 15
      csharp/reverse-string/README.md
  35. 7
      csharp/reverse-string/ReverseString.cs
  36. 17
      csharp/reverse-string/ReverseString.csproj
  37. 36
      csharp/reverse-string/ReverseStringTest.cs
  38. 21
      csharp/sum-of-multiples/README.md
  39. 9
      csharp/sum-of-multiples/SumOfMultiples.cs
  40. 17
      csharp/sum-of-multiples/SumOfMultiples.csproj
  41. 84
      csharp/sum-of-multiples/SumOfMultiplesTest.cs
  42. 21
      csharp/two-fer/README.md
  43. 7
      csharp/two-fer/TwoFer.cs
  44. 17
      csharp/two-fer/TwoFer.csproj
  45. 24
      csharp/two-fer/TwoFerTest.cs
  46. 56
      elixir/hello-world/README.md
  47. 9
      elixir/hello-world/hello_world.exs
  48. 14
      elixir/hello-world/hello_world_test.exs
  49. 54
      elixir/nucleotide-count/README.md
  50. 32
      elixir/nucleotide-count/nucleotide_count.exs
  51. 44
      elixir/nucleotide-count/nucleotide_count_test.exs
  52. 83
      elixir/protein-translation/README.md
  53. 33
      elixir/protein-translation/protein_translation.exs
  54. 92
      elixir/protein-translation/protein_translation_test.exs
  55. 72
      elixir/rotational-cipher/README.md
  56. 19
      elixir/rotational-cipher/rotational_cipher.exs
  57. 82
      elixir/rotational-cipher/rotational_cipher_test.exs
  58. 92
      elixir/secret-handshake/README.md
  59. 27
      elixir/secret-handshake/secret_handshake.exs
  60. 72
      elixir/secret-handshake/secret_handshake_test.exs
  61. 78
      elixir/strain/README.md
  62. 27
      elixir/strain/strain.exs
  63. 101
      elixir/strain/strain_test.exs
  64. 454
      fsharp/.gitignore
  65. 3
      fsharp/bob/Bob.fs
  66. 23
      fsharp/bob/Bob.fsproj
  67. 109
      fsharp/bob/BobTest.fs
  68. 1
      fsharp/bob/Program.fs
  69. 20
      fsharp/bob/README.md
  70. 3
      fsharp/hello-world/HelloWorld.fs
  71. 23
      fsharp/hello-world/HelloWorld.fsproj
  72. 13
      fsharp/hello-world/HelloWorldTest.fs
  73. 1
      fsharp/hello-world/Program.fs
  74. 21
      fsharp/hello-world/README.md
  75. 3
      fsharp/leap/Leap.fs
  76. 23
      fsharp/leap/Leap.fsproj
  77. 25
      fsharp/leap/LeapTest.fs
  78. 1
      fsharp/leap/Program.fs
  79. 33
      fsharp/leap/README.md
  80. 50
      ruby/.gitignore
  81. 43
      ruby/difference-of-squares/README.md
  82. 23
      ruby/difference-of-squares/difference_of_squares.rb
  83. 62
      ruby/difference-of-squares/difference_of_squares_test.rb
  84. 35
      ruby/gigasecond/README.md
  85. 9
      ruby/gigasecond/gigasecond.rb
  86. 47
      ruby/gigasecond/gigasecond_test.rb
  87. 57
      ruby/grains/README.md
  88. 14
      ruby/grains/grains.rb
  89. 70
      ruby/grains/grains_test.rb
  90. 66
      ruby/hamming/README.md
  91. 56
      ruby/hamming/RUNNING_TESTS.md
  92. 6
      ruby/hamming/hamming.rb
  93. 88
      ruby/hamming/hamming_test.rb
  94. 128
      ruby/hello-world/GETTING_STARTED.md
  95. 45
      ruby/hello-world/README.md
  96. 5
      ruby/hello-world/hello_world.rb
  97. 43
      ruby/hello-world/hello_world_test.rb
  98. 57
      ruby/leap/README.md
  99. 9
      ruby/leap/leap.rb
  100. 51
      ruby/leap/leap_test.rb

17
crystal/.gitignore

@ -0,0 +1,17 @@
.DS_Store
/.tags
/.tags_sorted_by_file
/.vagrant
.crystal/
coverage/
/deps/
/.build/
.*.swp
/Makefile.local
all_spec
/tmp
/docs/
/src/llvm/ext/llvm_ext.o
/src/llvm/ext/llvm_ext.dwo
/src/ext/*.o
/src/ext/libcrystal.a

78
crystal/hello-world/README.md

@ -0,0 +1,78 @@
# Hello World
The classical introductory exercise. Just say "Hello, World!".
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.
The objectives are simple:
- Write a function that returns the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.
If everything goes well, you will be ready to fetch your first real exercise.
## Project Structure
* `src` contains your solution to the exercise
* `spec` contains the tests to run for the exercise
## Running Tests
If you're in the right directory (i.e. the one containing `src` and `spec`), you can run the tests for that exercise by running `crystal spec`:
```bash
$ pwd
/Users/johndoe/Code/exercism/crystal/hello-world
$ ls
GETTING_STARTED.md README.md spec src
$ crystal spec
```
This will run all of the test files in the `spec` directory.
In each test file, all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by changing `pending` to `it`.
## Submitting Your Solution
Be sure to submit the source file in the `src` directory when submitting your solution:
```bash
$ exercism submit src/hello_world.cr
```
## Setup
Follow the setup instructions for Crystal here:
http://exercism.io/languages/crystal
More help installing can be found here:
http://crystal-lang.org/docs/installation/index.html
## Making the Test Suit Pass
Execute the tests with:
```bash
$ crystal spec
```
In each test suite all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by changing `pending` to `it`.
## Source
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

8
crystal/hello-world/spec/hello_world_spec.cr

@ -0,0 +1,8 @@
require "spec"
require "../src/*"
describe "HelloWorld" do
it "Say Hi!" do
HelloWorld.hello.should eq("Hello, World!")
end
end

2
crystal/hello-world/src/hello_world.cr

@ -0,0 +1,2 @@
# Please implement your solution to hello-world in this file
puts "Hello, World!"

33
csharp/.gitignore

@ -0,0 +1,33 @@
*.swp
*.*~
project.lock.json
.DS_Store
*.pyc
nupkg/
# Visual Studio Code
.vscode
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
[Oo]bj/
msbuild.log
msbuild.err
msbuild.wrn
# Visual Studio 2015
.vs/

10
csharp/accumulate/Accumulate.cs

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
public static class AccumulateExtensions
{
public static IEnumerable<U> Accumulate<T, U>(this IEnumerable<T> collection, Func<T, U> func)
{
foreach (var elem in collection) yield return func(elem);
}
}

17
csharp/accumulate/Accumulate.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

63
csharp/accumulate/AccumulateTest.cs

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Xunit;
public class AccumulateTest
{
[Fact]
public void Empty_accumulation_produces_empty_accumulation()
{
Assert.Equal(new int[0], new int[0].Accumulate(x => x * x));
}
[Fact]
public void Accumulate_squares()
{
Assert.Equal(new[] { 1, 4, 9 }, new[] { 1, 2, 3 }.Accumulate(x => x * x));
}
[Fact]
public void Accumulate_upcases()
{
Assert.Equal(new List<string> { "HELLO", "WORLD" }, new List<string> { "hello", "world" }.Accumulate(x => x.ToUpper()));
}
[Fact]
public void Accumulate_reversed_strings()
{
Assert.Equal("eht kciuq nworb xof cte".Split(' '), "the quick brown fox etc".Split(' ').Accumulate(Reverse));
}
private static string Reverse(string value)
{
var array = value.ToCharArray();
Array.Reverse(array);
return new string(array);
}
[Fact]
public void Accumulate_within_accumulate()
{
var actual = new[] { "a", "b", "c" }.Accumulate(c =>
string.Join(" ", new[] { "1", "2", "3" }.Accumulate(d => c + d)));
Assert.Equal(new[] { "a1 a2 a3", "b1 b2 b3", "c1 c2 c3" }, actual);
}
[Fact]
public void Accumulate_is_lazy()
{
var counter = 0;
var accumulation = new[] { 1, 2, 3 }.Accumulate(x => x * counter++);
Assert.Equal(0, counter);
accumulation.ToList();
Assert.Equal(3, counter);
}
[Fact]
public void Accumulate_allows_different_return_type()
{
Assert.Equal(new[] { "1", "2", "3" }, new[] { 1, 2, 3 }.Accumulate(x => x.ToString()));
}
}

37
csharp/accumulate/README.md

@ -0,0 +1,37 @@
# Accumulate
Implement the `accumulate` operation, which, given a collection and an
operation to perform on each element of the collection, returns a new
collection containing the result of applying that operation to each element of
the input collection.
Given the collection of numbers:
- 1, 2, 3, 4, 5
And the operation:
- square a number (`x => x * x`)
Your code should be able to produce the collection of squares:
- 1, 4, 9, 16, 25
Check out the test suite to see the expected function signature.
## Restrictions
Keep your hands off that collect/map/fmap/whatchamacallit functionality
provided by your standard library!
Solve this one yourself using other basic tools instead.
## Hints
This exercise requires you to write an extension method. For more information, see [this page](https://msdn.microsoft.com/en-us//library/bb383977.aspx).
## Source
Conversation with James Edward Gray II [https://twitter.com/jeg2](https://twitter.com/jeg2)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

20
csharp/bob/Bob.cs

@ -0,0 +1,20 @@
using System;
using System.Linq;
public static class Bob
{
public static string Response(string statement)
{
if (string.IsNullOrWhiteSpace(statement))
return "Fine. Be that way!";
if (statement.Any(Char.IsLetter) && statement.Where(Char.IsLetter).All(Char.IsUpper))
if (statement.Contains("?"))
return "Calm down, I know what I'm doing!";
else
return "Whoa, chill out!";
if (statement.Trim().EndsWith("?"))
return "Sure.";
return "Whatever.";
}
}

17
csharp/bob/Bob.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

156
csharp/bob/BobTest.cs

@ -0,0 +1,156 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.
using Xunit;
public class BobTest
{
[Fact]
public void Stating_something()
{
Assert.Equal("Whatever.", Bob.Response("Tom-ay-to, tom-aaaah-to."));
}
[Fact]
public void Shouting()
{
Assert.Equal("Whoa, chill out!", Bob.Response("WATCH OUT!"));
}
[Fact]
public void Shouting_gibberish()
{
Assert.Equal("Whoa, chill out!", Bob.Response("FCECDFCAAB"));
}
[Fact]
public void Asking_a_question()
{
Assert.Equal("Sure.", Bob.Response("Does this cryogenic chamber make me look fat?"));
}
[Fact]
public void Asking_a_numeric_question()
{
Assert.Equal("Sure.", Bob.Response("You are, what, like 15?"));
}
[Fact]
public void Asking_gibberish()
{
Assert.Equal("Sure.", Bob.Response("fffbbcbeab?"));
}
[Fact]
public void Talking_forcefully()
{
Assert.Equal("Whatever.", Bob.Response("Let's go make out behind the gym!"));
}
[Fact]
public void Using_acronyms_in_regular_speech()
{
Assert.Equal("Whatever.", Bob.Response("It's OK if you don't want to go to the DMV."));
}
[Fact]
public void Forceful_question()
{
Assert.Equal("Calm down, I know what I'm doing!", Bob.Response("WHAT THE HELL WERE YOU THINKING?"));
}
[Fact]
public void Shouting_numbers()
{
Assert.Equal("Whoa, chill out!", Bob.Response("1, 2, 3 GO!"));
}
[Fact]
public void Only_numbers()
{
Assert.Equal("Whatever.", Bob.Response("1, 2, 3"));
}
[Fact]
public void Question_with_only_numbers()
{
Assert.Equal("Sure.", Bob.Response("4?"));
}
[Fact]
public void Shouting_with_special_characters()
{
Assert.Equal("Whoa, chill out!", Bob.Response("ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!"));
}
[Fact]
public void Shouting_with_no_exclamation_mark()
{
Assert.Equal("Whoa, chill out!", Bob.Response("I HATE YOU"));
}
[Fact]
public void Statement_containing_question_mark()
{
Assert.Equal("Whatever.", Bob.Response("Ending with ? means a question."));
}
[Fact]
public void Non_letters_with_question()
{
Assert.Equal("Sure.", Bob.Response(":) ?"));
}
[Fact]
public void Prattling_on()
{
Assert.Equal("Sure.", Bob.Response("Wait! Hang on. Are you going to be OK?"));
}
[Fact]
public void Silence()
{
Assert.Equal("Fine. Be that way!", Bob.Response(""));
}
[Fact]
public void Prolonged_silence()
{
Assert.Equal("Fine. Be that way!", Bob.Response(" "));
}
[Fact]
public void Alternate_silence()
{
Assert.Equal("Fine. Be that way!", Bob.Response("\t\t\t\t\t\t\t\t\t\t"));
}
[Fact]
public void Multiple_line_question()
{
Assert.Equal("Whatever.", Bob.Response("\nDoes this cryogenic chamber make me look fat?\nno"));
}
[Fact]
public void Starting_with_whitespace()
{
Assert.Equal("Whatever.", Bob.Response(" hmmmmmmm..."));
}
[Fact]
public void Ending_with_whitespace()
{
Assert.Equal("Sure.", Bob.Response("Okay if like my spacebar quite a bit? "));
}
[Fact]
public void Other_whitespace()
{
Assert.Equal("Fine. Be that way!", Bob.Response("\n\r \t"));
}
[Fact]
public void Non_question_ending_with_whitespace()
{
Assert.Equal("Whatever.", Bob.Response("This is a statement ending with whitespace "));
}
}

22
csharp/bob/README.md

@ -0,0 +1,22 @@
# 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 answers 'Calm down, I know what I'm doing!' if you yell a question at him.
He says 'Fine. Be that way!' if you address him without actually saying
anything.
He answers 'Whatever.' to anything else.
## 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 Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

20
csharp/grade-school/GradeSchool.cs

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
public class School
{
public void Add(string student, int grade)
{
throw new NotImplementedException("You need to implement this function.");
}
public IEnumerable<string> Roster()
{
throw new NotImplementedException("You need to implement this function.");
}
public IEnumerable<string> Grade(int grade)
{
throw new NotImplementedException("You need to implement this function.");
}
}

17
csharp/grade-school/GradeSchool.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

85
csharp/grade-school/GradeSchoolTest.cs

@ -0,0 +1,85 @@
using Xunit;
public class GradeSchoolTest
{
[Fact]
public void Adding_a_student_adds_them_to_the_sorted_roster()
{
var school = new School();
school.Add("Aimee", 2);
var actual = school.Roster();
var expected = new[] { "Aimee" };
Assert.Equal(expected, actual);
}
[Fact(Skip = "Remove to run test")]
public void Adding_more_students_adds_them_to_the_sorted_roster()
{
var school = new School();
school.Add("Blair", 2);
school.Add("James", 2);
school.Add("Paul", 2);
var actual = school.Roster();
var expected = new[] { "Blair", "James", "Paul" };
Assert.Equal(expected, actual );
}
[Fact(Skip = "Remove to run test")]
public void Adding_students_to_different_grades_adds_them_to_the_same_sorted_roster()
{
var school = new School();
school.Add("Chelsea", 3);
school.Add("Logan", 7);
var actual = school.Roster();
var expected = new[] { "Chelsea", "Logan"};
Assert.Equal(expected, actual);
}
[Fact(Skip = "Remove to run test")]
public void Grade_returns_the_students_in_that_grade_in_alphabetical_order()
{
var school = new School();
school.Add("Franklin", 5);
school.Add("Bradley", 5);
school.Add("Jeff", 1);
var actual = school.Grade(5);
var expected = new[] { "Bradley", "Franklin" };
Assert.Equal(expected, actual);
}
[Fact(Skip = "Remove to run test")]
public void Grade_returns_an_empty_list_if_there_are_no_students_in_that_grade()
{
var school = new School();
var actual = school.Grade(1);
Assert.Empty(actual);
}
[Fact(Skip = "Remove to run test")]
public void Student_names_with_grades_are_displayed_in_the_same_sorted_roster()
{
var school = new School();
school.Add("Peter", 2);
school.Add("Anna", 1);
school.Add("Barb", 1);
school.Add("Zoe", 2);
school.Add("Alex", 2);
school.Add("Jim", 3);
school.Add("Charlie", 1);
var actual = school.Roster();
var expected = new[] { "Anna", "Barb", "Charlie", "Alex", "Peter", "Zoe", "Jim" };
Assert.Equal(expected, actual);
}
}

43
csharp/grade-school/README.md

@ -0,0 +1,43 @@
# Grade School
Given students' names along with the grade that they are in, create a roster
for the school.
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?
## Source
A pairing session with Phil Battos at gSchool [http://gschool.it](http://gschool.it)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

6
csharp/hello-world/HelloWorld.cs

@ -0,0 +1,6 @@
using System;
public static class HelloWorld
{
public static string Hello() => "Hello, World!";
}

17
csharp/hello-world/HelloWorld.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

12
csharp/hello-world/HelloWorldTest.cs

@ -0,0 +1,12 @@
// This file was auto-generated based on version 1.0.0 of the canonical data.
using Xunit;
public class HelloWorldTest
{
[Fact]
public void Say_hi_()
{
Assert.Equal("Hello, World!", HelloWorld.Hello());
}
}

23
csharp/hello-world/README.md

@ -0,0 +1,23 @@
# Hello World
The classical introductory exercise. Just say "Hello, World!".
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.
The objectives are simple:
- Write a function that returns the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.
If everything goes well, you will be ready to fetch your first real exercise.
## Source
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

9
csharp/leap/Leap.cs

@ -0,0 +1,9 @@
using System;
public static class Leap
{
public static bool IsLeapYear(int year)
{
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
}

17
csharp/leap/Leap.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

30
csharp/leap/LeapTest.cs

@ -0,0 +1,30 @@
// This file was auto-generated based on version 1.2.0 of the canonical data.
using Xunit;
public class LeapTest
{
[Fact]
public void Year_not_divisible_by_4_is_common_year()
{
Assert.False(Leap.IsLeapYear(2015));
}
[Fact]
public void Year_divisible_by_4_not_divisible_by_100_is_leap_year()
{
Assert.True(Leap.IsLeapYear(1996));
}
[Fact]
public void Year_divisible_by_100_not_divisible_by_400_is_common_year()
{
Assert.False(Leap.IsLeapYear(2100));
}
[Fact]
public void Year_divisible_by_400_is_leap_year()
{
Assert.True(Leap.IsLeapYear(2000));
}
}

35
csharp/leap/README.md

@ -0,0 +1,35 @@
# Leap
Given a year, report if it is a leap year.
The tricky thing here is that a leap year in the Gregorian calendar occurs:
```text
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
## Source
JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

31
csharp/nucleotide-count/NucleotideCount.cs

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
public class NucleotideCount
{
private string _seq;
private char[] keys = new[] {'A', 'C', 'G', 'T'};
public NucleotideCount(string sequence)
{
_seq = sequence;
if (_seq.Any(c => !keys.Contains(c))) throw new InvalidNucleotideException();
}
private int CountOne(char key)
=> _seq.Count(c => c == key);
public IDictionary<char, int> NucleotideCounts
{
get
{
var c = new Dictionary<char, int>();
foreach (var key in keys)
c.Add(key, CountOne(key));
return c;
}
}
}
public class InvalidNucleotideException : Exception { }

17
csharp/nucleotide-count/NucleotideCount.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

69
csharp/nucleotide-count/NucleotideCountTest.cs

@ -0,0 +1,69 @@
// This file was auto-generated based on version 1.2.0 of the canonical data.
using Xunit;
using System.Collections.Generic;
public class NucleotideCountTest
{
[Fact]
public void Empty_strand()
{
var sut = new NucleotideCount("");
var expected = new Dictionary<char, int>
{
['A'] = 0,
['C'] = 0,
['G'] = 0,
['T'] = 0
};
Assert.Equal(expected, sut.NucleotideCounts);
}
[Fact]
public void Can_count_one_nucleotide_in_single_character_input()
{
var sut = new NucleotideCount("G");
var expected = new Dictionary<char, int>
{
['A'] = 0,
['C'] = 0,
['G'] = 1,
['T'] = 0
};
Assert.Equal(expected, sut.NucleotideCounts);
}
[Fact]
public void Strand_with_repeated_nucleotide()
{
var sut = new NucleotideCount("GGGGGGG");
var expected = new Dictionary<char, int>
{
['A'] = 0,
['C'] = 0,
['G'] = 7,
['T'] = 0
};
Assert.Equal(expected, sut.NucleotideCounts);
}
[Fact]
public void Strand_with_multiple_nucleotides()
{
var sut = new NucleotideCount("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
var expected = new Dictionary<char, int>
{
['A'] = 20,
['C'] = 12,
['G'] = 17,
['T'] = 21
};
Assert.Equal(expected, sut.NucleotideCounts);
}
[Fact]
public void Strand_with_invalid_nucleotides()
{
Assert.Throws<InvalidNucleotideException>(() => new NucleotideCount("AGXXACT"));
}
}

25
csharp/nucleotide-count/README.md

@ -0,0 +1,25 @@
# Nucleotide Count
Given a single stranded DNA string, compute how many times each nucleotide occurs in the string.
The genetic language of every living thing on the planet is DNA.
DNA is a large molecule that is built from an extremely long sequence of individual elements called nucleotides.
4 types exist in DNA and these differ only slightly and can be represented as the following symbols: 'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' thymine.
Here is an analogy:
- twigs are to birds nests as
- nucleotides are to DNA as
- legos are to lego houses as
- words are to sentences as...
## Hints
This exercise requires the use of a Dictionary. For more information see
[this page.](https://msdn.microsoft.com/en-us/library/s4ys34ea(v=vs.110).aspx)
## Source
The Calculating DNA Nucleotides_problem at Rosalind [http://rosalind.info/problems/dna/](http://rosalind.info/problems/dna/)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

26
csharp/raindrops/README.md

@ -0,0 +1,26 @@
# Raindrops
Convert a number to a string, the contents of which depend on the number's factors.
- If the number has 3 as a factor, output 'Pling'.
- If the number has 5 as a factor, output 'Plang'.
- If the number has 7 as a factor, output 'Plong'.
- If the number does not have 3, 5, or 7 as a factor,
just pass the number's digits straight through.
## Examples
- 28's factors are 1, 2, 4, **7**, 14, 28.
- In raindrop-speak, this would be a simple "Plong".
- 30's factors are 1, 2, **3**, **5**, 6, 10, 15, 30.
- In raindrop-speak, this would be a "PlingPlang".
- 34 has four factors: 1, 2, 17, and 34.
- In raindrop-speak, this would be "34".
## Source
A variation on a famous interview question intended to weed out potential candidates. [http://jumpstartlab.com](http://jumpstartlab.com)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

20
csharp/raindrops/Raindrops.cs

@ -0,0 +1,20 @@
using System;
using System.Linq;
using System.Text;
public static class Raindrops
{
public static string Convert(int number)
{
var s = new StringBuilder();
if (number % 3 == 0)
s.Append("Pling");
if (number % 5 == 0)
s.Append("Plang");
if (number % 7 == 0)
s.Append("Plong");
if (new [] {3, 5, 7}.All(n => number % n != 0))
s.Append(number);
return s.ToString();
}
}

17
csharp/raindrops/Raindrops.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

114
csharp/raindrops/RaindropsTest.cs

@ -0,0 +1,114 @@
// This file was auto-generated based on version 1.0.0 of the canonical data.
using Xunit;
public class RaindropsTest
{
[Fact]
public void The_sound_for_1_is_1()
{
Assert.Equal("1", Raindrops.Convert(1));
}
[Fact]
public void The_sound_for_3_is_pling()
{
Assert.Equal("Pling", Raindrops.Convert(3));
}
[Fact]
public void The_sound_for_5_is_plang()
{
Assert.Equal("Plang", Raindrops.Convert(5));
}
[Fact]
public void The_sound_for_7_is_plong()
{
Assert.Equal("Plong", Raindrops.Convert(7));
}
[Fact]
public void The_sound_for_6_is_pling_as_it_has_a_factor_3()
{
Assert.Equal("Pling", Raindrops.Convert(6));
}
[Fact]
public void Number_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base()
{
Assert.Equal("8", Raindrops.Convert(8));
}
[Fact]
public void The_sound_for_9_is_pling_as_it_has_a_factor_3()
{
Assert.Equal("Pling", Raindrops.Convert(9));
}
[Fact]
public void The_sound_for_10_is_plang_as_it_has_a_factor_5()
{
Assert.Equal("Plang", Raindrops.Convert(10));
}
[Fact]
public void The_sound_for_14_is_plong_as_it_has_a_factor_of_7()
{
Assert.Equal("Plong", Raindrops.Convert(14));
}
[Fact]
public void The_sound_for_15_is_plingplang_as_it_has_factors_3_and_5()
{
Assert.Equal("PlingPlang", Raindrops.Convert(15));
}
[Fact]
public void The_sound_for_21_is_plingplong_as_it_has_factors_3_and_7()
{
Assert.Equal("PlingPlong", Raindrops.Convert(21));
}
[Fact]
public void The_sound_for_25_is_plang_as_it_has_a_factor_5()
{
Assert.Equal("Plang", Raindrops.Convert(25));
}
[Fact]
public void The_sound_for_27_is_pling_as_it_has_a_factor_3()
{
Assert.Equal("Pling", Raindrops.Convert(27));
}
[Fact]
public void The_sound_for_35_is_plangplong_as_it_has_factors_5_and_7()
{
Assert.Equal("PlangPlong", Raindrops.Convert(35));
}
[Fact]
public void The_sound_for_49_is_plong_as_it_has_a_factor_7()
{
Assert.Equal("Plong", Raindrops.Convert(49));
}
[Fact]
public void The_sound_for_52_is_52()
{
Assert.Equal("52", Raindrops.Convert(52));
}
[Fact]
public void The_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7()
{
Assert.Equal("PlingPlangPlong", Raindrops.Convert(105));
}
[Fact]
public void The_sound_for_3125_is_plang_as_it_has_a_factor_5()
{
Assert.Equal("Plang", Raindrops.Convert(3125));
}
}

15
csharp/reverse-string/README.md

@ -0,0 +1,15 @@
# Reverse String
Reverse a string
For example:
input: "cool"
output: "looc"
## Source
Introductory challenge to reverse an input string [https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb](https://medium.freecodecamp.org/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

7
csharp/reverse-string/ReverseString.cs

@ -0,0 +1,7 @@
using System;
using System.Linq;
public static class ReverseString
{
public static string Reverse(string input)=> string.Concat(input.ToCharArray().Reverse());
}

17
csharp/reverse-string/ReverseString.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

36
csharp/reverse-string/ReverseStringTest.cs

@ -0,0 +1,36 @@
// This file was auto-generated based on version 1.0.1 of the canonical data.
using Xunit;
public class ReverseStringTest
{
[Fact]
public void An_empty_string()
{
Assert.Equal("", ReverseString.Reverse(""));
}
[Fact]
public void A_word()
{
Assert.Equal("tobor", ReverseString.Reverse("robot"));
}
[Fact]
public void A_capitalized_word()
{
Assert.Equal("nemaR", ReverseString.Reverse("Ramen"));
}
[Fact]
public void A_sentence_with_punctuation()
{
Assert.Equal("!yrgnuh m'I", ReverseString.Reverse("I'm hungry!"));
}
[Fact]
public void A_palindrome()
{
Assert.Equal("racecar", ReverseString.Reverse("racecar"));
}
}

21
csharp/sum-of-multiples/README.md

@ -0,0 +1,21 @@
# Sum Of Multiples
Given a number, find the sum of all the unique multiples of particular numbers up to
but not including that number.
If we list all the natural numbers below 20 that are multiples of 3 or 5,
we get 3, 5, 6, 9, 10, 12, 15, and 18.
The sum of these multiples is 78.
## 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).
## 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.

9
csharp/sum-of-multiples/SumOfMultiples.cs

@ -0,0 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
public static class SumOfMultiples
{
public static int Sum(IEnumerable<int> multiples, int max)
=> Enumerable.Range(0, max).Where(c => multiples.Any(m => c % m == 0)).Sum();
}

17
csharp/sum-of-multiples/SumOfMultiples.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

84
csharp/sum-of-multiples/SumOfMultiplesTest.cs

@ -0,0 +1,84 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.
using Xunit;
public class SumOfMultiplesTest
{
[Fact]
public void Multiples_of_3_or_5_up_to_1()
{
Assert.Equal(0, SumOfMultiples.Sum(new[] { 3, 5 }, 1));
}
[Fact]
public void Multiples_of_3_or_5_up_to_4()
{
Assert.Equal(3, SumOfMultiples.Sum(new[] { 3, 5 }, 4));
}
[Fact]
public void Multiples_of_3_up_to_7()
{
Assert.Equal(9, SumOfMultiples.Sum(new[] { 3 }, 7));
}
[Fact]
public void Multiples_of_3_or_5_up_to_10()
{
Assert.Equal(23, SumOfMultiples.Sum(new[] { 3, 5 }, 10));
}
[Fact]
public void Multiples_of_3_or_5_up_to_100()
{
Assert.Equal(2318, SumOfMultiples.Sum(new[] { 3, 5 }, 100));
}
[Fact]
public void Multiples_of_3_or_5_up_to_1000()
{
Assert.Equal(233168, SumOfMultiples.Sum(new[] { 3, 5 }, 1000));
}
[Fact]
public void Multiples_of_7_13_or_17_up_to_20()
{
Assert.Equal(51, SumOfMultiples.Sum(new[] { 7, 13, 17 }, 20));
}
[Fact]
public void Multiples_of_4_or_6_up_to_15()
{
Assert.Equal(30, SumOfMultiples.Sum(new[] { 4, 6 }, 15));
}
[Fact]
public void Multiples_of_5_6_or_8_up_to_150()
{
Assert.Equal(4419, SumOfMultiples.Sum(new[] { 5, 6, 8 }, 150));
}
[Fact]
public void Multiples_of_5_or_25_up_to_51()
{
Assert.Equal(275, SumOfMultiples.Sum(new[] { 5, 25 }, 51));
}
[Fact]
public void Multiples_of_43_or_47_up_to_10000()
{
Assert.Equal(2203160, SumOfMultiples.Sum(new[] { 43, 47 }, 10000));
}
[Fact]
public void Multiples_of_1_up_to_100()
{
Assert.Equal(4950, SumOfMultiples.Sum(new[] { 1 }, 100));
}
[Fact]
public void Multiples_of_an_empty_list_up_to_10000()
{
Assert.Equal(0, SumOfMultiples.Sum(new int[0], 10000));
}
}

21
csharp/two-fer/README.md

@ -0,0 +1,21 @@
# Two Fer
`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
```text
"One for X, one for me."
```
When X is a name or "you".
If the given name is "Alice", the result should be "One for Alice, one for me."
If no name is given, the result should be "One for you, one for me."
## Source
[https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

7
csharp/two-fer/TwoFer.cs

@ -0,0 +1,7 @@
using System;
public static class TwoFer
{
public static string Name(string input = null)
=> $"One for {(input ?? "you")}, one for me.";
}

17
csharp/two-fer/TwoFer.csproj

@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Example.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
</ItemGroup>
</Project>

24
csharp/two-fer/TwoFerTest.cs

@ -0,0 +1,24 @@
// This file was auto-generated based on version 1.1.0 of the canonical data.
using Xunit;
public class TwoFerTest
{
[Fact]
public void No_name_given()
{
Assert.Equal("One for you, one for me.", TwoFer.Name());
}
[Fact]
public void A_name_given()
{
Assert.Equal("One for Alice, one for me.", TwoFer.Name("Alice"));
}
[Fact]
public void Another_name_given()
{
Assert.Equal("One for Bob, one for me.", TwoFer.Name("Bob"));
}
}

56
elixir/hello-world/README.md

@ -0,0 +1,56 @@
# Hello World
The classical introductory exercise. Just say "Hello, World!".
["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
the traditional first program for beginning programming in a new language
or environment.
The objectives are simple:
- Write a function that returns the string "Hello, World!".
- Run the test suite and make sure that it succeeds.
- Submit your solution and check it at the website.
If everything goes well, you will be ready to fetch your first real exercise.
## Running tests
Execute the tests with:
```bash
$ elixir hello_world_test.exs
```
### Pending tests
In the test suites, all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by
commenting out the relevant `@tag :pending` with a `#` symbol.
For example:
```elixir
# @tag :pending
test "shouting" do
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
end
```
Or, you can enable all the tests by commenting out the
`ExUnit.configure` line in the test suite.
```elixir
# ExUnit.configure exclude: :pending, trace: true
```
For more detailed information about the Elixir track, please
see the [help page](http://exercism.io/languages/elixir).
## Source
This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

9
elixir/hello-world/hello_world.exs

@ -0,0 +1,9 @@
defmodule HelloWorld do
@doc """
Simply returns "Hello, World!"
"""
@spec hello :: String.t()
def hello do
"Hello, World!"
end
end

14
elixir/hello-world/hello_world_test.exs

@ -0,0 +1,14 @@
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("hello_world.exs", __DIR__)
end
ExUnit.start()
ExUnit.configure(trace: true)
defmodule HelloWorldTest do
use ExUnit.Case
test "says 'Hello, World!'" do
assert HelloWorld.hello() == "Hello, World!"
end
end

54
elixir/nucleotide-count/README.md

@ -0,0 +1,54 @@
# Nucleotide Count
Given a single stranded DNA string, compute how many times each nucleotide occurs in the string.
The genetic language of every living thing on the planet is DNA.
DNA is a large molecule that is built from an extremely long sequence of individual elements called nucleotides.
4 types exist in DNA and these differ only slightly and can be represented as the following symbols: 'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' thymine.
Here is an analogy:
- twigs are to birds nests as
- nucleotides are to DNA as
- legos are to lego houses as
- words are to sentences as...
## Running tests
Execute the tests with:
```bash
$ elixir nucleotide_count_test.exs
```
### Pending tests
In the test suites, all but the first test have been skipped.
Once you get a test passing, you can unskip the next one by
commenting out the relevant `@tag :pending` with a `#` symbol.
For example:
```elixir
# @tag :pending
test "shouting" do
assert Bob.hey("WATCH OUT!") == "Whoa, chill out!"
end
```
Or, you can enable all the tests by commenting out the
`ExUnit.configure` line in the test suite.
```elixir
# ExUnit.configure exclude: :pending, trace: true
```
For more detailed information about the Elixir track, please
see the [help page](http://exercism.io/languages/elixir).
## Source
The Calculating DNA Nucleotides_problem at Rosalind [http://rosalind.info/problems/dna/](http://rosalind.info/problems/dna/)
## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

32
elixir/nucleotide-count/nucleotide_count.exs

@ -0,0 +1,32 @@
defmodule NucleotideCount do
@nucleotides [?A, ?C, ?G, ?T]
@doc """
Counts individual nucleotides in a NucleotideCount strand.
## Examples
iex> NucleotideCount.count('AATAA', ?A)
4
iex> NucleotideCount.count('AATAA', ?T)
1
"""
@spec count([char], char) :: non_neg_integer
def count(strand, nucleotide) do
Enum.count(strand, &(&1 == nucleotide))
end
@doc """
Returns a summary of counts by nucleotide.
## Examples
iex> NucleotideCount.histogram('AATAA')
%{?A => 4, ?T => 1, ?C => 0, ?G => 0}
"""
@spec histogram([char]) :: map
def histogram(strand) do
Map.new(@nucleotides, &{&1, count(strand, &1)})
end
end

44
elixir/nucleotide-count/nucleotide_count_test.exs

@ -0,0 +1,44 @@
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
Code.load_file("nucleotide_count.exs", __DIR__)
end
ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)
defmodule NucleotideCountTest do
use ExUnit.Case
# @tag :pending
test "empty dna string has no adenine" do