7
$\begingroup$

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.)

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – trolley813
    Dec 15, 2020 at 17:32

2 Answers 2

7
$\begingroup$

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; }

$\endgroup$
4
  • $\begingroup$ Great! You beat me for less than a minute. $\endgroup$
    – trolley813
    Dec 15, 2020 at 17:31
  • $\begingroup$ 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; } $\endgroup$
    – Bubbler
    Dec 15, 2020 at 23:21
  • $\begingroup$ @Bubbler that's a good point, I may add that into the answer (with credit) if that's okay as it provides good context. $\endgroup$
    – hexomino
    Dec 15, 2020 at 23:31
  • $\begingroup$ @hexomino Sure, no problem. $\endgroup$
    – Bubbler
    Dec 15, 2020 at 23:33
5
$\begingroup$

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$).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.