1

I have the numbers 1 - 100, when they are put into a box (an abstracted code function I do not know the details of), they come out as

0 = 1
1 = 4
2 = 6
3 = 9
4 = 11
5 = 14
6 = 16
7 = 19
8 = 21
9 = 24
10 = 26
11 = 29
12 = 31
13 = 34
14 = 36
15 = 39
16 = 41
17 = 44
18 = 47
19 = 49
20 = 52
21 = 54
22 = 57
23 = 59
24 = 62
25 = 64
26 = 67
...
100 = 254

I know the range that comes out of the box (code) is 1-254 .. If someone can help me unravel reversing the equation this uses, that would be amazing

ie original output of the code produces 4 when it is given 1. I want to give my code 4 and get back 1

convert(output);
value = convert(4);

# value would be 1; etc

cgmckeever
  • 113
  • 4
  • 1
    There are an infinite number of functions that satisfy the conditions you have given. If you want one function that produces the sequence in your code, you'll likely need to provide all of the data. We can't infer with absolute certainty what happens over the interval $(7,100)$. – Brian61354270 Nov 24 '19 at 19:30
  • working on it --- – cgmckeever Nov 24 '19 at 19:51
  • it appears the pattern stays consistent as +3 then +2 alternating .. Im actually looking to figure out how to take the output given and get the original input (updating the question to be more clear) .. such as I give my function 4 and it returns 1 – cgmckeever Nov 24 '19 at 20:06

3 Answers3

1

Looks like the difference between the 0th term and the 1st term is 3. The difference between the 1st term and the 2nd term is $2$. So the difference between consecutive terms alternates between $2$ and $3$. One way to represent this is with the ceiling function:

$f(x) = 1 + \lceil2.5x\rceil$

jwc845
  • 661
  • Thank you -- I though this was spot on, when I tried it, 10 == 26 was a match; 40 == 102 did not work ... I am trying to get a complete pattern now – cgmckeever Nov 24 '19 at 19:50
  • Like Brian said in the comment to the question. We can't know for with 100% certainty since there are infinite functions that can match any set of inputs and outputs you provide. – jwc845 Nov 24 '19 at 19:54
  • working through getting all the values, but it appears that it is following the 2 then 3 alternating .. I also realized Im actually asking to reverse the equation, so given the OUTPUT (ie 254) I can get 100 .. still trying to have Alexa feed me all these values ;) – cgmckeever Nov 24 '19 at 20:02
1

hint

For each $n$ ,

$$u_{2n+1}=u_{2n}+3$$

$$u_{2n+2}=u_{2n+1}+2$$

Let $V_n=u_{2n}$.

then $$V_{n+1}=V_n+5$$ with $V_0=1$. thus $$V_n=V_0+5n=1+5n=u_{2n}$$

By the same, you get $$u_{2n+1}=5n+4$$

0

The differences (seem to) alternate between $2$ and $3$. That means the odd and even positions each form an arithmetic progression with difference $5$.

That should be enough information for you to reconstruct the convert function. There's no really clean "formula".

Edit in answer to comments. The following algorithm correctly makes the calculation based on the previous observation, but that observation does not match the data. The comments explain what's going on.

The output number $y$ will always leave a remainder $r$ of $1$ or $4$ when you divide it by $5$. To recover the input $x$:

Let $$ z = \frac{(y-r)}{5}. $$ Then $$ x = \begin{cases} 2z & \text{ if } r = 1 \\ 2z+ 1 & \text{ if } r = 4 . \end{cases} $$

Ethan Bolker
  • 95,224
  • 7
  • 108
  • 199
  • Thanks Ethan .. any more hints to help me? I rephrased my question to be more clear as well. Im looking to create a function that given the output of the backbox returns the input -- such as 4 returns 1 – cgmckeever Nov 24 '19 at 20:07
  • @cgmckeever See my edit. – Ethan Bolker Nov 24 '19 at 20:31
  • whoa -- this is tight ... working on the code side, but it is making sense from my napkin math .. THANK YOU – cgmckeever Nov 24 '19 at 20:33
  • This is amazing Ethan .. .it seems to fall apart in higher numbers, shown by 254 == 100 -- your calc would have a remainder of 4; (254 - 4)/5 = 50; 2 * (50) + 1 ... Im trying to see where it deviates .. my math could be really off here – cgmckeever Nov 24 '19 at 20:49
  • I just looked more carefully. The function is more complex than we thought. There's a gap of $6$ between inputs $16$ and $18$. I fear you will need the whole table of outputs and just do a table lookup to reverse the calculation. – Ethan Bolker Nov 24 '19 at 20:51
  • Pretty sure ... This is an ALEXA thing, I give her a level of 0-100, and she sends the device 1-254 ... also 51 returns 130 .. – cgmckeever Nov 24 '19 at 20:54
  • Good catch on that +6 ... I just feel this is some computery thing to go between 1-100 and 0-254 .. really appreciate what you tried .. – cgmckeever Nov 24 '19 at 20:56
  • ALEXA is just doing a linear interpolation of the range $[0,100]$ to $[1,254]$ adn rounding to get integers. Solve your problem with a table lookup - better than a formula with tricky rounding. – Ethan Bolker Nov 24 '19 at 20:56
  • Your equation is probably close enough for me to determine input level +/- 1 – cgmckeever Nov 24 '19 at 21:03
  • Don't bother with my equation. Just do the linear interpolation and round to the nearest integer. https://en.wikipedia.org/wiki/Linear_interpolation – Ethan Bolker Nov 24 '19 at 21:28
  • LOL . thanks .. holy crap, got to dig into that some ;) – cgmckeever Nov 24 '19 at 22:48