2
$\begingroup$

I have a set of scores $s \in[1;40]$, where $s$ is integer. I want to map each score to a index, like this:

$1 \le s \le 5 \to 0 \\ 6 \le s \le 10 \to 1 \\ 11 \le s \le 20 \to2\\ 21 \le s \le 30 \to3\\ 31 \le s \le 40 \to4\\ $

So basically I am looking for a function which would map the score to the index. I have tried with logs and algebraic functions (is that the term?) but since the intervals are not the same (5 for the first, 10 for the second, 10 for the third, &c.) I don't know how to get around this.

  • 0
    @HagenvonEitzen: Thanks for the tip, but this time I'm not particularly concerned with speed. So I would say I can ignore the difference in performance between a lookup table and two division operations.2012-09-28

2 Answers 2

2

Using Heaviside step function $H$, this is $ \bigg\lceil\frac{s}{10}\bigg\rceil-H(5-s). $

  • 0
    The two answers are both great, but I'm choosing this one just because I think it's simpler!2012-09-29
3

$f(s)=\left\lfloor\frac {s-1}{10}\right\rfloor +\left\lfloor\frac {s+34}{40}\right\rfloor$

  • 1
    Any function $f:\{1,\ldots,n\}\to\mathbb R$ can be written as $\sum_{k=0}^{n-1}a_k\left\lfloor\frac{x+k}n\right\rfloor$ by taking $a_k=f(n-k)-f(n-k-1)$. Of course summands with $a_k=0$ can be dropped, and sometimes you can simplify.2012-09-28