Decimals -> Fraction strings, my solution

François Pinard pinard at iro.umontreal.ca
Wed May 17 15:42:43 EDT 2000


Michael Hudson <mwh21 at cam.ac.uk> writes:

> You have the right approach (continued fractions), but you're
> implementation is more complex than it needs to be.  [...]  Same numbers
> as before, but rather less effort to get them, I think.

Thanks for sharing this.  Your solution computes a single continued
fraction to the maximum precision, and then uses it to show the successive
approximations up to that maximum precision.  Which surely is a good thing.
My solution computes a single continued fraction, but stops the computation
when some error tolerance has been reached.  I then called the whole thing
many times to make experiments, resulting indeed in much total work.

In practice, I guess it is programmatically easier to decide of some
tolerance in advance, and find a single solution from it, than to find
all solutions up to the maximum precision possible, and later scan all
these to decide which is one that should be retained.  Yours is surely
more entertaining when used interactively! :-)

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list