Did you look at the link provided to Continued Fractions?

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:

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
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.

(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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.