5
0
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 ? '\\' :
It would help to know what those expressions are. – Leaky Nun – 2017-05-18T03:57:24.063
yup, updated. try not to distracted by golfing them :) – Steve Bennett – 2017-05-18T03:58:58.350
Well,
(i-r)%8
can becomei-r&7
:p – Leaky Nun – 2017-05-18T03:59:34.653I still can't see what your
D
is. – Leaky Nun – 2017-05-18T04:00:30.443Updated again... – Steve Bennett – 2017-05-18T04:01:54.917
You're still hiding part of your
D
. – Leaky Nun – 2017-05-18T04:02:21.007