Beispiel #1
0
        public static RuleSet ParseRules(this IInputLines lines)
        {
            var twoByTwo     = ImmutableArray.CreateBuilder <Rule>();
            var threeByThree = ImmutableArray.CreateBuilder <Rule>();

            foreach (var line in lines.AsString())
            {
                var split = line.Split("=>", StringSplitOptions.TrimEntries);

                var length = split[0].Length;
                var rules  = ParseRule(split[0], split[1])
                             .Distinct();

                if (length == 5)
                {
                    twoByTwo.AddRange(rules);
                }
                else if (length == 11)
                {
                    threeByThree.AddRange(rules);
                }
            }

            return(new RuleSet(
                       twoByTwo.ToImmutable(),
                       threeByThree.ToImmutable()));
        }
Beispiel #2
0
    public static Graph ParseGraph(this IInputLines lines)
    {
        var links = new Dictionary <string, List <string> >();

        foreach (var line in lines.AsString())
        {
            var split = line.Split('-', StringSplitOptions.TrimEntries);

            AddEdge(links, split[0], split[1]);
        }

        return(new Graph(links));
Beispiel #3
0
 public static string[] AsArray(this IInputLines lines)
 => lines.AsString().ToArray();