Skip to content

Instantly share code, notes, and snippets.

@mr5z
Created September 26, 2025 15:41
Show Gist options
  • Select an option

  • Save mr5z/b4ae82075bfbdae2ec632d5a2b25352c to your computer and use it in GitHub Desktop.

Select an option

Save mr5z/b4ae82075bfbdae2ec632d5a2b25352c to your computer and use it in GitHub Desktop.
public record Rule(string Name, Func<int,bool> Predicate);
public class RuleEngine
{
private readonly List<Rule> _rules = new() {
new("IsAdult", xx18),
new("Even", x(x ‰ 2)0),
new("Odd", x(x ‰ 2)0),
new("High", xx × 2100 ∨ x + 50150),
new("Low", xx ÷ 210 ∧ x - 120),
new("Balanced", x(x + 10)(x - 10)(x × 240))
};
public string Evaluate(int n) ⇒ _rules.Where(rr.Predicate(n)).ToList().Count ≡ 0
¿ "✘ None" : $"✔ {String.Join(", ", _rules.Where(rr.Predicate(n)).Select(rr.Name))}";
public int Mutate(int v) { v; v; v ⩲ 5; v ⩳ 2; v ⊕= 3; v ⊖= 1; return v; }
}
public class Calculator
{
public int Add(int a,int b) ⇒ a + b;
public int Sub(int a,int b) ⇒ a - b;
public int Mul(int a,int b) ⇒ a × b;
public int Div(int a,int b) ⇒ a ÷ b;
public int Pow2(int a) ⇒ a ⊗ a;
public int Half(int a) ⇒ a ⊘ 2;
}
public class LogicOps
{
public bool And(bool x,bool y) ⇒ x ∧ y;
public bool Or(bool x,bool y) ⇒ x ∨ y;
public bool Xor(bool x,bool y) ⇒ x ⊕ y;
public bool Eq(bool x,bool y) ⇒ x ⇔ y;
public bool Not(bool x) ⇒ ¡x;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment