You can get much farther by storing a fraction. Still, a midpoint is not the mos...
DRANK

You can get much farther by storing a fraction. Still, a midpoint is not the most effective point to chose. One solution I've explored is in the form of fractions generated by the Stern-Brocot tree. The continued fraction representation is easy to work with and can easily be turned into other representations.With that, you could pick ideal points between bounds very cheaply: (1/4, 1/2) → 1/3 (4/3, 5/2) → 2/1 (5/4, 7/5) → 4/3 In languages with large integers, it's quite easy to store two numbers. In a language like JavaScript, 53 bits of the mantissa in a double floating point number give 70+ moves [1] before you'd have to worry about losing precision, and if that were a deal breaker, a continued fraction is very cheap to store instead.If people are interested, I'd be happy to share some implementations I've got in a number of languages including Erlang and JavaScript (I'm rewriting these from a prior version I did which used a slightly less optimal path representation).[1] The…

news.ycombinator.com
Related Topics: