public IEnumerable <BfsNode> Bfs(SearchConfig config)
        {
            var initialParser = new RootParser();
            var initialStates = initialParser.AcceptableStructuralChars().Select(c => new BfsNode
            {
                Json   = new[] { c },
                Parser = initialParser.Read(c)
            });
            var queue = new Queue <BfsNode>();

            QueueAll(queue, initialStates);

            var count = 0;

            while (queue.Any())
            {
                count++;
                var next = queue.Dequeue();

                // Is this one of the winning states we're looking for?
                if (config.IsSuccessState(next))
                {
                    yield return(next);
                }

                // Don't queue if the current node can never lead to a solution node
                if (config.CanLeadToSuccessState(next))
                {
                    var nextStates = NextStates(next).ToList();
                    QueueAll(queue, nextStates);
                }
            }

            Console.Out.WriteLine($"Searched states: {count}");
        }
        public bool IsValidJson(string json)
        {
            JsonParser parser = new RootParser();

            foreach (var c in json)
            {
                if (!parser.AcceptableChars().Contains(c))
                {
                    return(false);
                }

                parser = parser.Read(c);
            }

            return(parser.CanBeTheEndOfInput);
        }
        public string RandomWalk()
        {
            var s      = "[";
            var parser = new RootParser().Read('[');

            for (var i = 0; i < 250; i++)
            {
                // var nextChar = RandomElement(parser.AcceptableChars());
                var nextChars = parser.AcceptableChars().ToList();
                if (!nextChars.Any())
                {
                    break;
                }

                var next = RandomElement(nextChars);
                s     += next;
                parser = parser.Read(next);
            }

            return(s);
        }