5

A && B && !C ? x : A && C ? y : x

Comments
  • 5
    Whenever I see something written like that I swear I take at least 2d6 points of psychic damage. Unless they're writing for some extremely limited hardware it costs nothing to put it into ifs and then you don't need to ponder upon how many colons you've gone through to remember which clause you are at. If there is more than one colon in your ternary you failed.
  • 3
    @msdsk "if" won’t make it more readable. Subexpressions replaced by properly named variables will.
  • 0
    A && (!C || B) ? x : y
  • 5
    @kiki I don't think that's correct.

    for example, if I substitute A = true, B = true, C = true

    then the original expression would return "y"

    but your expression would return "x"

    I think it should just be

    A && C ? y : x

    the value of B is irrelevant. If B is true, it's up to (A && !C) for x to occur and if B is false it's up to ~(A && C) for x to occur... so x can only occur if (A && !C) || ~(A && C). But ~(A && C) is true only if either A, C or both are false, so it already covers the case of (A && !C) where only C is false... so it can be further simplified to just ~(A && C) ? x : y... but then the ~ would be just extra to we drop that too to get (A && C) ? y : x

    I hope I didn't miss something xD but I think this is correct
  • 2
    @Hazarth
    Course it isn't.
    It's a professional influencer distractor from a disinformation center.
    Sure can spend some time in correcting such accounts, but that's their aim: to steal your time.
  • 1
    @Hazarth Pretty much it.
  • 3
    Why am I feeling the urge to make a Karnaugh map of this.
  • 3
    @Lensflare
    fair, though once I tried to write it down using an if it became absurdly obvious that it could be written by the simple ternary of A && C ? y : x just because the formatting made it visible at the first glance. So I guess both.
Add Comment