Home > OS >  Formula for x with this pattern?
Formula for x with this pattern?

Time:07-23

x is a number from 1 to 10.

What could be the formula for x with this pattern?

x = 1 -> output 0
x = 2 -> output 1
x = 3 -> output 2
x = 4 -> output 3
x = 5 -> output 4
x = 6 -> output 0
x = 7 -> output 1
x = 8 -> output 2
x = 9 -> output 3
x = 10 -> output 4

I came up with

x % 5 - 1

but does not work when x = 5 or x = 10

CodePudding user response:

You were close, just move the subtraction operation before the modulo operation

(x - 1) % 5
  •  Tags:  
  • math
  • Related