How to build a function that shows a number changed using a max distance between them?

28 Views Asked by At

I stuck in some problem, lets say I have:

  • the max distance between two numbers are 5 (difference)
  • x is an integer greater than 1
  • w is an unique integer number generated by function f
  • z is an unique integer number generated by function f and is different from w

E.G.:

f(x) = w

f(x+1) = w

...

f(x+maxDistance) = z (the number has changed because x+maxDistance is greater or equal than 5)


*Note: the input values (x, x+1, and x+maxDistance) don't know each other, I want to use the return value to check if the number surpassed the value only using the return of function.


A real example to give more context to my problem, I have a chronometer that is counting the time:

In a certain moment, it is showing the number 4

In another moment, it shows the number 6 (2 seconds elapsed)

So I want to make a function with that conditions:

f(4) = 1

f(6) = 1 ( 6-4 <= 5 ? true )

...

f(10) = 2 (10-4 <= 5 ? false)

See that the return value changed 1 to 2? Thats what I want, the input numbers don't know each other, 1 and 2 can be x and y but they must be different.