you are viewing a single comment's thread
view the rest of the comments
[–] 3 points 1 year ago (2 children)

Not to take from all the funny answers ... but

bool IsEven(int i) => (i & 1) != 1;

(C#)

  • source
  • hideshow 2 child comments
  • [–] 2 points 1 year ago (1 child)

    Though, obviously I had to come up with some ridiculous solutions:

    bool IsEven(int i) => ((Func<string, bool>)(s => s[^1] == 48))($"{i:B}");
    

    This one works without conditionals :)

    bool IsEven(int i)
    {
        try
        {
            int _ = (i & 1) / (i & 1);
        }
        catch (Exception)
        {
            return true;
        }
    
        return false;
    }
    
  • source
  • parent
  • hideshow 1 child comment