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.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
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
 

Tyman2007

Ya Rly >.
Reaction score
74
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)
 

Azlier

Old World Ghost
Reaction score
461
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.
 

ZakkWylde-

New Member
Reaction score
14
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).
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
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))
 

ZakkWylde-

New Member
Reaction score
14
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
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
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.
:)
 

jwallstone

New Member
Reaction score
33
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.
 

ZakkWylde-

New Member
Reaction score
14
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)
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
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.

      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