[Tutor] help finding recurring cycle

bob gailer bgailer at gmail.com
Wed Dec 24 03:48:51 CET 2008


Kent Johnson wrote:
> On Tue, Dec 23, 2008 at 8:20 PM, col speed <ajarncolin at gmail.com> wrote:
>
>   
>> I've written a "division" function that gives more decimal places than the
>> one already in python. What my poor old brain can't work out is how to find
>> a "recurring cycle" which isn't disastrously complicated (as the cycle
>> doesn't always include the first decimal places and the length is unknown).
>>     
>
> I would look for repetition in the remainder (the dividend) at each
> step. Perhaps keep a dict which maps dividend to position, then when
> you get a repeat you can figure out how long the cycle is.
>
> Kent
>   

Check out http://en.wikipedia.org/wiki/Repeating_decimal.

Section 5 How a repeating or terminating decimal expansion is found 
illustrates the above.

-- 
Bob Gailer
Chapel Hill NC 
919-636-4239



More information about the Tutor mailing list