How to simplify modulus expression?

1k Views Asked by At

Currently I have

4 - (X % (Y % (X - 4)))

It looks like I can have a simpler term than this. enter image description here

I just need last 4 rows to have 4, 3, 2, 1

Not sure whether there is a simpler equation!

1

There are 1 best solutions below

1
On

$$Y\bmod (X-4)=X-k,k>4$$ Which means:$$X\bmod(Y\bmod(X-4))\equiv X-(X-k)\equiv k, \quad\text{if}\quad k\leq\frac{X}{2}$$

Which means half the time your value is $4-k$

The real problem, is dealing with finding k and working the other half of the time. Without a general use of variables, There's less chance that it can be put as something simpler in all cases.