Something like this maybe?
string previous = string.Empty; while (b != previous) { previous = b; b = b.Replace("true and false", "false"); b = b.Replace("true and true", "true"); b = b.Replace("false and true", "false"); b = b.Replace("false and false", "false"); b = b.Replace("false or false", "false"); b = b.Replace("true or false", "true"); b = b.Replace("true or true", "true"); b = b.Replace("false or true", "true"); b = b.Replace("(false)", "false"); b = b.Replace("(true)", "true"); b = b.Replace("not false", "true"); b = b.Replace("not true", "false"); }
Please note that the specification is ambiguous, such as:
"false and false or true" "false and true or true"
Both of these expressions are “true” if “evaluted” first and “false” if first evaluated or evaluated. Therefore, requiring brackets at each level would be better. Requiring an assessment from left to right is another option, but it makes the code more complex.
For those of you who can object to this style of solution for this style of problem, remember that some mathematicians believe that all this mathematics can be reduced to this kind of manipulation of symbols. said one of Russell and Whitehead’s main criticisms of the Mathematics Principle is that it embodies formulas with too much meaning.
source share