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.
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top