2
input:  0, 1, 2, 3, 0, 1, 2, 3...
output: 0, 1, 1, 0, 0, 1, 1, 0...

I'm trying to resolve a function that takes the input and produces the corresponding output but despite how simple it looks, i can't quite seem to figure it out. Any suggestions?

Nataly
  • 23

3 Answers3

2

While what you've written already defines a function on $\{0,1,2,3\}$, you could express it as a polynomial like

$$f(x)=\frac{3x-x^2}{2}.$$

This particular form comes from observing that the values are symmetric around $x=1.5$ and fitting a parabola to them.

AMPerrine
  • 3,043
2

$$ f(n)= \begin{cases} 1, & n+1\text{ is prime}\\ 0, & \text{otherwise} \end{cases}. $$

You can adapt it for increasing values $(4,5,6,\ldots)$ by working modulo $4$.

Workaholic
  • 6,763
2

I assume here you mean that the function just keeps repeating the pattern of $0$, $1$, $1$, $0$ as the input values increase.

There are several ways to do it. Here's a silly way:

$$f(x)=\begin{cases}0&\text{if }x\equiv0,3\pmod{4}\\1&\text{if }x\equiv1,2\pmod{3}\end{cases}$$

And here's a slightly cleverer way: $$f(x)=\left\lfloor\frac{x}{2}+\frac{1}{2}\right\rfloor\mod2$$

Here $\lfloor a\rfloor$ denotes the greatest integer less than or equal to $a$, and $a\mod b$ denotes the remainder when $a$ is divided by $b$.