# What function is it?

A function of one variable $$y = f(x)$$. However, I suspect that the function does not need to necessarily be strictly mathematical.

If $$x = 1$$, then $$y = 0$$.

If $$x = 2$$, then $$y = 0$$.

If $$x = 10$$, then $$y = 9$$.

If $$x = 3$$, then $$y = 3$$.

If $$x = 20$$, then $$y = 18$$.

If $$x = 1990$$, then $$y = 1989$$.

What function is it? (A puzzle from an old informatics textbook which I was unable to solve for years.)

• The "old informatics textbook" seems to be from around 1990, since the authors of such problems often use the current year as a "sufficiently large" integer. Dec 15, 2020 at 17:32

It looks like

$$y = 3 \lfloor \frac{x}{3} \rfloor$$

where

$$\lfloor . \rfloor$$ is the floor function indicating the greatest integer less than or equal to the argument.

Similarly

$$y$$ is the greatest integer $$\leq x$$ which is divisible by $$3$$.

Given that it comes from an informatics textbook Bubbler make an important point that

some programming is relevant here (and it must be C if it's from 1990): int f(int x) { return x / 3 * 3; }

• Great! You beat me for less than a minute. Dec 15, 2020 at 17:31
• Given that it's from an informatics textbook, I guess some programming is relevant here (and it must be C if it's from 1990): int f(int x) { return x / 3 * 3; } Dec 15, 2020 at 23:21
• @Bubbler that's a good point, I may add that into the answer (with credit) if that's okay as it provides good context. Dec 15, 2020 at 23:31
• @hexomino Sure, no problem. Dec 15, 2020 at 23:33

An alternative (and very similar) answer (which still fits):

$$f(x) = x - L_{10}(x) \bmod 3$$, where $$L_{10}(x)$$ is the leftmost (nonzero as usual) digit of $$x$$ written in decimal (i.e. $$L_{10}(534)=5, L_{10}(6207)=6$$ etc.). (The hexomino's answer is simply $$f(x)=x-x\bmod3$$).