Reverse Javascript Math function

function gameDetails(lessthan) {
  var maxwin   = 8000000;
  var multi    = sigDigits(65536 / lessthan * .99, 5);
  var maximum  = Math.round(sigDigits((maxwin / multi), 2));
  var odds    = (lessthan / 65536 * 100).toPrecision(3);
}

function sigDigits(n, sig) {
    var mult;
    mult = Math.pow(10, sig - Math.floor(Math.log(n) / Math.LN10) - 1);
    return Math.floor(n * mult) / mult;
}

Hello,

I have the following form that i need to change dinamically:


the function gameDetails above changes the maxbet, odds and multiplier according to it.

I’m having truble doing a function where i define the odds/multiplier and get the other 3 vars.

All suggestions or advice are welcome.

Thank you.

You mean you are having trouble updating the form dynamically?

i’ve having truble with the math

What part of it? I don’t really understand your question.

so i need to build new functions where i give the multi var and get the lessthan, maximum and odds values

example:

function gameMulti(multi) {
lessthan = ?
maximum = ?
odds = ?
}

Here is an example of how it’s done.

Starting from the formula for multi, you want to solve for less than instead.
var multi = sigDigits(65536 / lessthan * .99, 5);

The sigDigits is a process that cannot be undone, so we can ignore that, which leaves us with:
multi = 65536 / lessthan * .99

Divide both sides by 0.99 to get
multi / 0.99 = 65536 / lessthan

Invert both sides so that lessthan is on top of the fraction:
0.99 / multi = lessthan / 65536

And multiply both sides by 65536 to end up with:
0.99 / multi * 65536 = lessthan

You can then reorder to get:
lessthan = 0.99 * 65536 / multi

1 Like

Because the sigDigits cannot be reversed, I recommend that you don’t use it on the variables, and only apply sigDigits to the computer screen output instead.

function gameDetails(lessthan) {
var maxwin = 8000000;
var multi = 65536 / lessthan * .99, 5;
var maximum = maxwin / multi;
var odds = lessthan / 65536 * 100
}

So to reverse those, we’ve done lessthan already to get

lessthan = 0.99 * 65536 / multi

Let’s do the others too.

With maximum, we already have a value for maxwin, so we can solve for multi:
maximum = maxwin / multi

Invert both sides to get:
1 / maximum = multi / maxwin

Then multiply by maxwin to get:
maxwin / maximum = multi

Which gives us:

multi = maxwin / maximum;

We can use the same maximum formula to solve for maxwin too:
maximum = maxwin / multi

Just multiply by multi to get:
maximum * multi = maxwin

Which gives us:

maxwin = maximum * multi

And lastly we can solve for lessthan
odds = lessthan / 65536 * 100

Divide by 100 to get:
odds / 100 = lessthan / 65536

And multiply by 65536:
odds * 65536 / 100 = lessthan

Giving an end result of:

odds * 65536 / 100 = lessthan

All of these formulas put together are:

lessthan = odds * 65536 / 100
maxwin = maximum * multi
maximum = maxwin / multi

You say that you have the odds and the multiplier, and you want to get the three other values, those being lessthan, maxwin, and maximum.

With odds we can get lessthan, but that doesn’t give us anything to help us get further. maxwin forms a triangle with maximum and multi. With one missing we can solve for that, but with two missing it’s not possible gain any further results.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.