Sure, the approach there is more complex, but the method provided does a better job of producing a rapidly converging sequence of fractional approximations than yours does. Modifying it to stop when the next approximation is more than 100, I produce the following output on your dataset:
For half of them it found the actual fraction. For the other half it was never off by more than 0.0001. If you let it go to a denominator of 1000, it correctly identified every fraction, and put it in lowest terms.2/57 = 0.0350877192982456 1/27 = 0.037037037037037 3/77 = 0.038961038961039 3/73 = 0.0410958904109589 4/93 = 0.043010752688172 4/87 = 0.0459770114942529 1/21 = 0.0476190476190476 4/69 = 0.0579710144927536 3/44 = 0.0681818181818182 6/77 = 0.0779220779220779 7/20 = 0.35 37/100 = 0.37 39/100 = 0.39 41/100 = 0.41 43/100 = 0.43 23/50 = 0.46 12/25 = 0.48 29/50 = 0.58 17/25 = 0.68 39/50 = 0.78
(There are other tricks that I used there, like a GCD algorithm that is completely general and more efficient than trial division.)
In reply to Re: Re: Percentages to Fractions
by tilly
in thread Percentages to Fractions
by David Caughell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |