How would I make this equation into a function WC3 can understand?

Tyman2007

Ya Rly >.
Reaction score
74
yeah, I have an equation and I made a post on how to use "to the power of"

I failed horribly.

I asked on what would be the equation to get this set of numbers

Code:
1, 20
2, 30
3, 40
4, 60
5, 80
6, 120
7, 160
8, 240
9, 320
10, 480

Someone responded

Here's a single formula that works for your entire list:

f(n) = 10·( 2^⌊n/2⌋ + 2^⌊(n-1)/2⌋ )

where ⌊x⌋ = largest integer m with m ≤ x,
usually pronounced "floor of x".

So I tried making that formula into something WC3 can understand and it didn't work out so well.

I probably mis-read the answer horribly. Just got into geo so... yeah my math is a little rough.

This is my attempt:
JASS:
function GetGivinXP takes integer n returns real
    local real a = I2R(n)/2
    local real b = I2R(n)-1
    local real c = Pow(2,a)
    local real d = Pow(2,b)
    local real e = d/2
    local real f = c + e
    local real g = 10-f
    return g
endfunction


I got this:
Code:
1, 8
2, 7
3, 5
4, 2
5, -3

I'll just stop right there.

Any ideas?

(Ps. I think I got it wrong, it might be *, not - for g. The dot confuses me.)

EDIT: Tried * instead of - for g, was really close! was actually around
Code:
1, 20
2, 30
3, 45
4, 80
5, 130

or something along those lines.
 
I haven't checked whether that function really works for your list, but here's how you could code it:

Conveniently, WC3 always rounds integers down, making integer math by default like a "floor" operation.

JASS:
function GetGivinXP takes integer n returns real
    local integer a = n/2
    local integer b = (n-1)/2
    local real c = Pow(2, I2R(a))
    local real d = Pow(2, I2R(b))
    local real e = c + d
    local real f = 10*e
    return f
endfunction


Or, inlined:

JASS:
function GetGivinXP takes integer n returns real
    return 10*(Pow(2, I2R(n/2)) + Pow(2, I2R((n-1)/2)))
endfunction
 
hehe, I forgot you can do it like that. It's my sworn duty to complicate things.
(I played I wanna be the guy)
The equation works and it matches with my set of numbers.
inlined works like a dream.

+rep.
(I has a feeling you shall be one of our next 1000+ posts members =P)
 
JASS:
function GetGivinXP takes integer n returns real
    return 10*(Pow(2, I2R(n/2)) + Pow(2, I2R((n-1)/2)))
endfunction

Just in case you didn't realize, this doesn't inline.
 
uhh....whoever told you that equation lied....

Looking at the first value: 1

According to what you want from the function, plugging in 1 should yield 20.

f(n) = 10·( 2^⌊n/2⌋ + 2^⌊(n-1)/2⌋ )

f(1) = 10*(2^1/2 + 2^0) = 10( squareroot of 2 + 1)

That is approximately 10*(1.41+1) = 24.1 ?? 24.1 does not equal 20.
-------------------------
Second value: 2

f(n) = 10·( 2^⌊n/2⌋ + 2^⌊(n-1)/2⌋ )

f(2) = 10*(2^1 + 2^(1/2 )
approximately... 10*(2*1.41) = 28.1. Again, it is not 30 (thought closer than the first value)
-------------------------
Third value: (I'm gonna skip 3 for ease, and just go to 4) -- 4
f(n) = 10·( 2^⌊n/2⌋ + 2^⌊(n-1)/2⌋ )

f(4) = 10*(2^2 + 2^(3/2) ) = 10*(4+2.828) which yields approximately 68.2 ... which is not 60.

Admittedly, it is KIND OF a good estimate...but if the numbers matter, the equation does not work. I'll try and think of one that does...=D (so I'm not just bashing)

EDIT: I dunno about the values you want...You'd have to have separate equations for groups of numbers...like maybe 1 and 2 could use the same equation, 3 and 4 could use another, etc...

The reason I say this is because the numbers you have do not go up geometrically...instead...they go up (starting from 1 to 2) +10, +10, +20, +20, +40, +40, +60, +60, +160 (? Maybe you meant 380 in which case it'd be +60 again...I dunno)

but uh...I know of no function that could go up like that...

WHAT YOU COULD DO...is plug in the values into excel, make it a graph, and get the line of best fit. It'll probably end up giving you a complicated equation, but it'd be more accurate than anything one of us could come up with on the top of our heads.

(SUCH A LONG POST, Sorry for long read, hope its helpful).
 
uhh....whoever told you that equation lied....
Only because you didn't read his post fully/correctly :)

It's not 10·( 2^(n/2) + 2^((n-1)/2) )

It's 10·( 2^⌊n/2⌋ + 2^⌊(n-1)/2⌋ )

AKA:
10·(2^TRUNCATION(n/2)+2^TRUNCATION((n-1)/2))
 
Call me stupid. Trunkating ftw.

I was thinking along the lines of an actual function...

Trunkating doesn't allow for the graph of that to actually be a function...

i.e., it's not one-to-one

and: Damn, I spent so much time on that :banghead:

Hehe....:p
 
I was thinking along the lines of an actual function...

Trunkating doesn't allow for the graph of that to actually be a function...

i.e., it's not one-to-one
Functions don't have to be one-to-one to be 'actual' functions.

Just because this function is noncontinuous and isn't one-to-one doesn't make it a not-function.

Call me stupid.
You're stupid.
:)
 
Since when does a function have to be one-to-one?

EDIT: As an example, both uberfoop and I took the post and mapped it to the same response at the same time. This function f(responder) -> post was not one-to-one.
 
Yeah...I lied some more... xD

...yeah...I mixed up some facts about functions.


BUT...for every x value there is only ONE y value. (yeah one-to-one is a two-way street...heh)
 
Put them into array and set the value seperately. No need calculation more. :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top