Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

<ItemGroup>
<PackageReference Include="NBuilder" Version="6.1.0" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions CodingChallenge.FamilyTree.Tests/FamilyTreeGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CodingChallenge.FamilyTree;
using System.Linq;
using FizzWare.NBuilder;

namespace CodingChallenge.FamilyTree.Tests
Expand Down
27 changes: 25 additions & 2 deletions CodingChallenge.FamilyTree/Solution.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
using System;
using System.Linq;

namespace CodingChallenge.FamilyTree
{
//I understood this to be a recursion problem. The issue I had was climb the stack back out when I found the name. At first I did not have the last return "" wrapped in the else, and everything was returning "".
public class Solution
{
public string GetBirthMonth(Person person, string descendantName)
{
throw new NotImplementedException();
//Here is your check for recursion exit
if (person.Name.ToLower() == descendantName.ToLower())
{
return person.Birthday.ToString("MMMM");
}

//Check to make sure your not at the bottom of the tree i.e. Not found
if (person.Descendants.Any())
{
//recursively go down the left
var left = GetBirthMonth(person.Descendants[0], descendantName);
// if you hit the bottom and climbing out, and there is a right side start going down
if (left == "" && person.Descendants.Count > 1)
{
return GetBirthMonth(person.Descendants[1], descendantName);
}
return left;
}
else
{
//Not Found
return "";
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions CodingChallenge.PirateSpeak.Tests/PirateSpeakTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class PirateSpeakTests
[TestCase("ainstuomn", new[] { "mountains", "hills", "mesa" }, new[] { "mountains" })]
[TestCase("oopl", new[] { "donkey", "pool", "horse", "loop" }, new[] { "pool", "loop" })]
[TestCase("oprst", new[] {"sport", "ports", "ball", "bat", "port"}, new[] {"sport", "ports"})]
[Test]
public void TestPirateVocabulary(string jumble, string[] dictionary, object expectedResult)
{
var actualResult = new Solution().GetPossibleWords(jumble, dictionary);
Expand Down
26 changes: 25 additions & 1 deletion CodingChallenge.PirateSpeak/Solution.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace CodingChallenge.PirateSpeak
{
//I saw this as a two possible solutions
//1.one use a FIFO stack so you dont get reuse duplication
//2.my solution which was get a group by with counts for both words and do a equals compare
public class Solution
{
public string[] GetPossibleWords(string jumble, string[] dictionary)
{
throw new NotImplementedException();
var result = new List<string>();
//do this here so it only happens once, order by is important so you can do a true compare
var jumbleCharArray = jumble.ToLower().GroupBy(x => x).Select(x => new { Char = x.Key, Count = x.Count()}).OrderBy(x => x.Char);

foreach (var word in dictionary)
{
//in your test project you have port and ports port wasn't defined as a passing test, so if the strings aren't same length continue.
if(word.Length != jumble.Length)
{
continue;
}

//order by is important so you can do a true compare
var wordCharArray = word.ToLower().GroupBy(x => x).Select(x => new { Char = x.Key, Count = x.Count()}).OrderBy(x => x.Char);
if (jumbleCharArray.SequenceEqual(wordCharArray))
{
result.Add(word);
}
}

return result.ToArray();
}
}
}