public RuleDay19 CreateRule(string input) { var ruleData = Regex.Match(input, ruleCreationPattern); var id = int.Parse(ruleData.Groups[1].Value); var ruleValue = ruleData.Groups[2].Value.Replace("\"", ""); var newRule = new RuleDay19(id, ruleValue); return(newRule); }
public void UpgradeRule11(RuleDay19 rule8) { for (int i = 2; i < 10; i++) { var duplicate42 = string.Concat(Enumerable.Repeat("42 ", i)); var duplicate31 = string.Concat(Enumerable.Repeat("31 ", i)); string result = duplicate42 + duplicate31; rule8.Rule += " | " + result; } }
//Not very effective public RuleDay19 CreateSimplifiedRule(RuleDay19 rule, List <RuleDay19> rules) { var rulesToReplace = GetRulesToReplace(rule); var aStringBuilder = new StringBuilder(rule.Rule); foreach (var ruleToReplace in rulesToReplace.OrderByDescending(i => i.Index)) { ReplaceSubRule(ruleToReplace, aStringBuilder, rules); } var newRule = aStringBuilder.ToString(); var newRuleObject = new RuleDay19(rule.Id, newRule); return(newRuleObject); }
public bool IsMessageValid(RuleDay19 rule, string message) { return(Regex.Match(message, rule.Rule).Success); }
private List <RuleToReplaceDay19> GetRulesToReplace(RuleDay19 rule) { var nestedRules = Regex.Matches(rule.Rule, rulePattern); return(CreateNestedRules(nestedRules)); }
public void UpgradeRule8(RuleDay19 rule8) { rule8.Rule = "(" + rule8.Rule + ")+"; }