The procedure for reducing a repeating decimal fraction to a proper fraction is thus:

First, assign x to be equal to the repeating fraction:

x = 0.571428(571428 ...)

Next, figure out the repeating decimal period. In this case, it repeats every six digits. Write down the fact that 10^(period)x equals whatever it equals:

1000000x = 571428.571428(571428 ...)

Now you have two equations. If you subtract the first equation from the second equation, the fraction cancels itself out, since it repeats to infinity in both numbers:

1000000x - x = 571428.571428(571428 ...) - 0.571428(571428 ...)
999999x = 571428

Now just solve for x and reduce the fraction to normal form:

x = 571428/999999 = 4/7

By the way, the traditional algorithm for finding the greatest common divisor (which is very useful in reducing fractions) is the Euclidean algorithm, which can be defined thusly:

def euclid(a, b):

if b == 0:
return a
else:
return euclid(b, a mod b)
Also, repeating decimals are traditionally shown by simply drawing a line over the repeating part, but I don't have that facility here. I was going to use an underline, but since HTML has been disabled ....

Now, I'd have to take exception to your assumption that the numbers must be small. If it's something that they do often enough, I'm sure that they bothered to write a simple application to allow them to type in the number and return the resultant number without them having to do it by hand. The fact that they know what the function is does not mean that they are applying it by hand.

On the other hand, the fact that they don't realize that multiplying by one number and dividing by another is nearly the definition of a fraction doesn't speak highly of their intelligence. And there are any number of one-way functions that would be as easy to program and much more secure.


Edited by wfaulk (29/11/2001 22:42)
_________________________
Bitt Faulk