0
$\begingroup$

I am doing a website and I need an algorithm. I am not so good in math, that is why I come here for help. It is, from my point, for a mathematician very easy.

Here's the deal :

IF X IS BETWEEN 0 AND 9     Y = 2  IF X IS BETWEEN 10 AND 19     Y = 4  IF X IS BETWEEN 20 AND 39     Y = 8  IF X IS BETWEEN 40 AND 79     Y = 16  IF X IS BETWEEN 80 AND 159     Y = 32  ETC... 

Anyone can help by doing a simple algorithm ? You can use any functions you want or whatever. Thanks a lot !

EDIT: It is possible to change the interval between X but it need to start low and be higher then Y and has to give similar results.

  • 0
    Something that I can run on a computer. I'm really no expert. Like X + 2 or f(x) = 2(x-2) - 1. etc... you can use function or whatever you need.2012-01-25

1 Answers 1

4

Divide $x$ by 10, multiply by 4, take the base-2 logarithm, round down to an integer $n$, then $y=2^n$. This doesn't work for $x$ between 0 and 5, so just define $y$ to be 2 in that range.

  • 0
    Final PHP Code : `$Y = ceil( pow(2, log(($X / 10) * 4, 2)) / 2);`2012-01-25