1
If input >= 32 And input < 64 Then
    output = 126 - input
ElseIf input >= 64 And input < 96 Then
    output = 126 + 64 - input
ElseIf input >= 96 And input <= 126 Then
    output = 126 + 32 - input
End If

It looks like it has something to do with Modulo 32 of input? Output is always an integer (no decimals).

If you find the solution, can you let me know how you go about solving this question?

1 Answers1

2

There is no really nice way of stating this function. $$ f(x) = 126 - x + \begin{cases} 0 & \text{if } 32 \le x < 64 \\ 64 & \text{if } 64 \le x < 96 \\ 32 & \text{if } 96 \le x < 128 \\ \end{cases} $$ The problem is that "$0, 64, 32$" doesn't have any really nice pattern. Of course, you can always artificially create this pattern anyway, using a quadratic equation: $$ f(x) = 126 - x + 16\left(\left\lfloor{\frac{x}{32}} \right\rfloor - 1\right) \left(10 - 3\left\lfloor{\frac{x}{32}} \right\rfloor\right) $$ I found this by first observing the piecewise bit was essentially a function of $\left\lfloor{\frac{x}{32}} \right\rfloor$. Then I got WolframAlpha to give me the quadratic equation through $(1, 0), (2, 64)$ and $(3, 32)$.

  • Thank you, I will try to get more practice with wolfram alpha, but I studied mathematics 15 years ago and not in English, so I'm having trouble with the terminology now. This helps a lot. – Vincent De Smet May 14 '14 at 05:54
  • @Vincent You're welcome, I am happy to help. Let me know if I used any terms you don't understand. – Caleb Stanford May 14 '14 at 05:55
  • What is the query you enter in wolfram alpha? quadratic equation {(1,0),(2,64),(3,32)} gives me a polynomial of degree 2 while your function looks easier – Vincent De Smet May 14 '14 at 06:17
  • 1
    @Vincent You should get like $-48x^2 + 208x - 160$. Then just type in factor -48x^2 + 208x - 160. – Caleb Stanford May 14 '14 at 06:34
  • oh, I feel stupid. Thanks, I got the polynomial from Excel trendline as well, but factor is something Excel can't do as fast. – Vincent De Smet May 14 '14 at 06:38