1
$\begingroup$

I'm trying to create a mathematical operation that help me to resolve this scenario.

I have a list of "limits" as show below:

0---4---8---12... (n + 4)

Suppose that we have a software that "read" a number, an it determines what is the previous "step limit". For example:

Given | Previous limit step 3     | 1 (the limit would be 0) 4     | 2 (the limit would be 4) 7     | 2 (the limit would be 4) 9     | 3 (the limit would be 8) 

What I need to do is trying to get the previous limit in question, as show below:

Given | Previous limit 3     | 0 4     | 4 7     | 4 9     | 8 

I have two days dealing with a formula to get it, but no good results.

  • 0
    I feel so stupid.. viewing the results as table I think that the formula is `limit = 4(n-1)`2012-10-12

1 Answers 1

1

$x - (x \text{ mod } 4)$ should be what you are looking for. $\text{a mod b}$ returns the remainder of $a$ divided by $b$, i.e. what remains of $a$ if you subtract $b$ is many times as possible without making the result negative. In a of programming languages, operator "%" means $\text{mod}$, so you'd write x - (x % 4) to compute your "previous limit".

  • 0
    You are correct2012-10-13