Beispiel #1
0
 public static SingleTypeExpression <int, TContext> WithOps <TContext>(this SingleTypeExpression <int, TContext> expr)
 {
     expr.AddBinary(new BinarySymbol("+", 1), (a, b) => a + b);
     expr.AddBinary(new BinarySymbol("-", 1), (a, b) => a - b);
     expr.AddBinary(new BinarySymbol("*", 2), (a, b) => a * b);
     expr.AddBinary(new BinarySymbol("/", 2), (a, b) => a / b);
     expr.AddUnary(new UnarySymbol("-"), i => - i);
     return(expr);
 }
Beispiel #2
0
    public override void PartTwo()
    {
        var expr = new SingleTypeExpression <long>(long.Parse);

        expr.AddBinary(new BinarySymbol("+", 2), (a, b) => a + b);
        expr.AddBinary(new BinarySymbol("*", 1), (a, b) => a * b);
        var sum = Input.Select(expr.Eval).Sum();

        WriteLn(sum);
    }