private static List<string> GetPossiblePasscodes(string attempt, string nextAttempt) { if (attempt == nextAttempt) return new List<string> { attempt }; var root = new CodeNode(string.Empty, attempt, nextAttempt); var toProcess = new Queue<CodeNode>(); toProcess.Enqueue(root); var result = new List<string>(); while (toProcess.Count > 0) { var codeNode = toProcess.Dequeue(); if (codeNode.IsComplete) { result.Add(codeNode.Stem); continue; } if (codeNode.NextCharSame) { toProcess.Enqueue(codeNode.TakeBoth()); continue; } if (codeNode.NextLeftInRight) { toProcess.Enqueue(codeNode.TakeRightUpToFirstLeft()); continue; } if (codeNode.NextRightInLeft) { toProcess.Enqueue(codeNode.TakeLeftUpToFirstRight()); continue; } toProcess.Enqueue(codeNode.TakeLeft()); toProcess.Enqueue(codeNode.TakeRight()); } return result; }
public void TakeAllRightUpToCommonLeftChar(string stem, string left, string right, string expectedStem, string expectedLeft, string expectedRight) { var original = new CodeNode(stem, left, right); var result = original.TakeRightUpToFirstLeft(); Assert.AreEqual(expectedStem, result.Stem, "Stem"); Assert.AreEqual(expectedLeft, result.RemainingLeft, "Left"); Assert.AreEqual(expectedRight, result.RemainingRight, "Right"); }