// Count how many strings match rule 0. public string PartOne(string[] lines) { var chunks = lines.ChunkBy(string.IsNullOrEmpty, true).Select(Enumerable.ToArray).ToArray(); var compiler = new RuleToRegexCompiler(chunks[0]); return(chunks[1].Count(line => Regex.IsMatch(line, compiler.RuleZeroRegex)).ToString()); }
// Count how many strings match rule 0 if rules 8 and 11 were modified to loop with themselves. public string PartTwo(string[] lines) { var chunks = lines.ChunkBy(string.IsNullOrEmpty, true).Select(Enumerable.ToArray).ToArray(); var compiler = new RuleToRegexCompiler(chunks[0], loopRules: new Dictionary <int, string> { { 8, "42 8" }, { 11, "42 11 31" } }, longestInputSize: chunks[1].Max(s => s.Length)); return(chunks[1].Count(line => Regex.IsMatch(line, compiler.RuleZeroRegex)).ToString()); }