Skip to content

Commit

Permalink
Merge pull request #89 from robkeim/grains
Browse files Browse the repository at this point in the history
Add Grains solution
  • Loading branch information
ErikSchierboom authored Aug 31, 2016
2 parents ba352ae + 54cc69e commit b6c05c0
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
10 changes: 9 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"rna-transcription",
"sum-of-multiples",
"space-age",
"grains",
"hamming",
"raindrops",
"nucleotide-count",
Expand Down Expand Up @@ -131,6 +132,13 @@
"Filtering"
]
},
{
"slug": "grains",
"difficulty": 2,
"topics": [
"Integers"
]
},
{
"slug": "raindrops",
"difficulty": 2,
Expand Down Expand Up @@ -307,7 +315,7 @@
{
"slug": "allergies",
"difficulty": 4,
"topics": [
"topics": [
"Bitwise operations",
"Filtering"
]
Expand Down
21 changes: 21 additions & 0 deletions exercises/grains/Example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
public class Grains
{
public static ulong Square(int n)
{
return n == 1
? 1
: 2 * Square(n - 1);
}

public static ulong Total()
{
ulong total = 0;

for (int i = 1; i <= 64; i++)
{
total += Square(i);
}

return total;
}
}
60 changes: 60 additions & 0 deletions exercises/grains/GrainsTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using NUnit.Framework;

[TestFixture]
public class GrainsTest
{
[Test]
public void Test_square_1()
{
Assert.That(Grains.Square(1), Is.EqualTo(1));
}

[Ignore("Remove to run test")]
[Test]
public void Test_square_2()
{
Assert.That(Grains.Square(2), Is.EqualTo(2));
}

[Ignore("Remove to run test")]
[Test]
public void Test_square_3()
{
Assert.That(Grains.Square(3), Is.EqualTo(4));
}

[Ignore("Remove to run test")]
[Test]
public void Test_square_4()
{
Assert.That(Grains.Square(4), Is.EqualTo(8));
}

[Ignore("Remove to run test")]
[Test]
public void Test_square_16()
{
Assert.That(Grains.Square(16), Is.EqualTo(32768));
}

[Ignore("Remove to run test")]
[Test]
public void Test_square_32()
{
Assert.That(Grains.Square(32), Is.EqualTo(2147483648));
}

[Ignore("Remove to run test")]
[Test]
public void Test_square_64()
{
Assert.That(Grains.Square(64), Is.EqualTo(9223372036854775808));
}

[Ignore("Remove to run test")]
[Test]
public void Test_total_grains()
{
Assert.That(Grains.Total(), Is.EqualTo(18446744073709551615));
}
}

0 comments on commit b6c05c0

Please sign in to comment.