Kent Johnson wrote:
On Tue, Dec 23, 2008 at 8:20 PM, col speed <ajarnco...@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

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to