I have an expression that could be expressed as either of :
a += (A ? B ? x : C ? y : D : D);
a += (A && B ? x : A && C ? y : D);
where A,B,C are expressions of 5-10 bytes each, and x and y are single character literals (3-4 bytes). D is another chain of ternaries (without the branching problem).
I'm getting stuck trying to eliminate the duplication of D or A. If I was using if
, it would be something like this:
if (A)
if (B)
x
else if (C)
y
else D
Obviously I could do ((z=A) && B ? x : z && C ? y : D)
...but any other more creative suggestions?
The actual code looks something like:
if (r%4<2&&r>3&&c<22&&c>1)
if ((i-r)%8==6)
'\\'
else if ((i+r)%8==1)
'/'
else
D is something like:
(i+r) % 8 == 3 ? '/' :
(c-r+16) % 8 == 4 ? '\\' :
(i-r)%8
can becomei-r&7
:p \$\endgroup\$D
is. \$\endgroup\$