private async Task <long> Part2() { var(rules, values) = await ParseInput(); rules[8] = new OtherRule(8, new List <List <int> > { new List <int> { 42 }, new List <int> { 42, 8 } }); rules[11] = new OtherRule(11, new List <List <int> > { new List <int> { 42, 31 }, new List <int> { 42, 11, 31 } }); var regexes = new Dictionary <int, string>(); while (!regexes.ContainsKey(31) || !regexes.ContainsKey(42)) { var toProcess = rules.Keys.Except(regexes.Keys); foreach (var i in toProcess) { if (rules[i].TryGetRegex(regexes, out string regex)) { regexes[i] = regex; } } } return(values.Count(v => { var trimmed = v; var regex42 = new Regex($"^{regexes[42]}"); var regex31 = new Regex($"^{regexes[31]}"); var matched = string.Empty; var count42 = 0; var count31 = 0; while (regex42.IsMatch(trimmed)) { var match = regex42.Match(trimmed); count42++; matched += match.Value; trimmed = trimmed.Substring(match.Value.Length); } while (regex31.IsMatch(trimmed)) { var match = regex31.Match(trimmed); count31++; matched += match.Value; trimmed = trimmed.Substring(match.Value.Length); } return matched == v && trimmed == string.Empty && count42 > count31 && count31 > 0; })); }
/// <summary> /// Copy constructor /// </summary> /// <param name="Other">Filter to copy from</param> public FileFilter(FileFilter Other) : this(Other.DefaultNode.Type) { foreach (FileFilterNode OtherRule in Other.Rules) { AddRule(OtherRule.ToString(), OtherRule.Type); } }
/// <summary> /// Copy constructor /// </summary> /// <param name="Other">Filter to copy from</param> public FileFilter(FileFilter Other) : this() { foreach (FileFilterNode OtherRule in Other.Rules) { AddRule(OtherRule.ToString(), OtherRule.bInclude); } }