#invert an equation?

17 messages · Page 1 of 1 (latest)

plucky plume
#

I know this doesnt have a lot to do with godot but how could I invert this function so that given only the result of this function i could independently find the original value of s

prime blade
#

What exactly does this function do?

plucky plume
#

its some math for map generation that pseudo randomly varies a seed given another seed

prime blade
#

This doesn't seem reversible to me

plucky plume
#

so if I ran var f = d(10000000) the value of f would be 9990000

#

hmm

#

everything is doable

prime blade
#

Like is this a continuous function, mathematically?

#

Is it possible for two different s values to give the same result?

plucky plume
#

oh im not actually sure

#

the part of most unsure about is the modulo part because im not quite sure how that would be reversible

prime blade
#

You also have an integer division in there

#

I suspect this is probably possible, but it probably isn't a simple formula

summer forge
#

It's not possible; even assuming that s is an integer, too much data is lost

#

If you put 9016 and 8999 into the function d, you will notice that both return 9007

#

This function just does the brute force method, and will always return a valid number that, when plugged through d, will be correct - but due to data loss it will not always be the original number. (Assuming that all numbers are integers, given that d will crash if the number isn't an integer)

func reverse(r):
  var tests = [r - r/1001, r + r/999]

  for i in range(tests.size()):
    if (d(tests[i]) == r):
      return tests[i]
summer forge