fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static bool DoTest(string sProp)
  7. {
  8. Regex re = new Regex(@"~\([A-Z0-1]\)|[&|>=]\([A-Z0-1],[A-Z0-1]\)");
  9.  
  10. while(re.Match(sProp).Success)
  11. {
  12. sProp = re.Replace(sProp, "1");
  13. }
  14. return sProp=="1";
  15. }
  16.  
  17. public static void Main()
  18. {
  19. string[] saPropositions = {
  20. "&(&(=(A,B),>(&(A,B),~(C))),>(A,~(&(A,B))))",
  21. "=(~(A),>(>(B,C),~(A)))",
  22. "(~(A))",
  23. ">(A,B"
  24. };
  25.  
  26.  
  27. for( int idx = 0; idx<saPropositions.Length; idx++)
  28. {
  29.  
  30. Console.WriteLine("Testing the proposition " + saPropositions[idx] + ".");
  31. Console.WriteLine(DoTest(saPropositions[idx]) ? "The proposition is valid"
  32. : "Invalid proposition");
  33.  
  34. }
  35. }
  36. }
Success #stdin #stdout 0.04s 134592KB
stdin
Standard input is empty
stdout
Testing the proposition &(&(=(A,B),>(&(A,B),~(C))),>(A,~(&(A,B)))).
The proposition is valid
Testing the proposition =(~(A),>(>(B,C),~(A))).
The proposition is valid
Testing the proposition (~(A)).
Invalid proposition
Testing the proposition >(A,B.
Invalid proposition