public override object PartOne(string[] input) { var edges = ParseDirectedEdges(input); var bfsConfig = new BfsSearchConfig <List <string> > { InitialState = new List <string> { "start" }, IsSuccessState = path => path.Last() == "end", NextStates = (path) => { var last = path.Last(); var possibleWaysToGo = edges .Where1(cave => cave == last) .Select2() .Where(cave => IsLargeCave(cave) || !path.Contains(cave)); return(possibleWaysToGo.Select(next => path.Append(next).ToList())); } }; var bfs = new BreadthFirstSearch <List <string> >(bfsConfig); var paths = bfs.Bfs().ToList(); return(paths.Count); }
public void ShouldFindDeepSolution() { var config = new BfsSearchConfig <int> { InitialState = 0, IsSuccessState = x => x == 1000, NextStates = x => new[] { x + 1, x - 1 }, SeenKey = i => i }; var bfs = new BreadthFirstSearch <int>(config); var firstResult = bfs.Bfs().First(); firstResult.Should().Be(1000); }