简体   繁体   English

具有这种模式的 x 的公式?

[英]Formula for x with this pattern?

x is a number from 1 to 10. x 是一个从 1 到 10 的数字。

What could be the formula for x with this pattern?具有这种模式的 x 的公式可能是什么?

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但当 x = 5 或 x = 10 时不起作用

你很接近,只需将减法运算移到模运算之前

(x - 1) % 5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM