News for hackers. Stuff that matters.
Re:Fun with math: Dividing one by 998001 yields a surprising... by psykotic on Thursday January 26, 2012 @12:20PM (#3514969)
There's some sleight of hand here. Not all the digits are exactly right. Look how it skips from 997 to 999:

http://www.futilitycloset.com/2012/01/08/math-notes-76/

Here's the math. Suppose you want a unit fraction 1/n with decimals that cycle through the 4-digit sequence abcd. Multiply by 10^4 to shift abcd into integer position, leaving repeating copies after the decimal point:

    10^4/n = abcd + 1/n
Solving for n gives n = (10^4 - 1) / abcd.

More generally, if you want to get a cycle equal to the d digits of an integer k, you want n = (10^d - 1) / k.

However, this only gives a true unit fraction when k divides 10^d - 1, so that n is an integer. Otherwise you are forced to truncate n and getting an approximate version of the cycle.

That's exactly what happened here: 10^d - 1 is not divisible by the integer 001002...998999.

Here's a small Python program that will generate the unit fraction given the number of digits to cycle through:

    import sys

    n = int(sys.argv[1])
    s = ''.join(("%0" + str(n) + "d") % (i,) for i in range(10**n))
    print "1/%d" % ((10**len(s) - 1) / int(s),)
Usage:

    $ python magic.py 3
    1/998001
    $ python magic.py 4
    1/99980001
This has just the right flavor for a Project Euler problem.
Re:Fun with math: Dividing one by 998001 yields a surprising... by bdg on Thursday January 26, 2012 @12:29PM (#3515013)
I just want to know I appreciate you posting this. Some people might be interested in "wow math sure can do some funky stuff", but others like myself really want to know why. I figure that's also covers a sizable group of us here on Hacker News.
Re:Fun with math: Dividing one by 998001 yields a surprising... by toasterweasel on Thursday January 26, 2012 @09:20PM (#3516920)
It does indeed. I have a love/hate relationship with math. Love because it's fascinating and intergal to an understanding of our universe, hate because I had some horrible math teachers over the years...plus I do admit to being slightly lazy.
Re:Fun with math: Dividing one by 998001 yields a surprising... by jklp on Thursday January 26, 2012 @11:55PM (#3517200)
There is no why. It just is. This is the worst thing about being human :)

http://www.smbc-comics.com/index.php?db=comics&id=1914

Re:Fun with math: Dividing one by 998001 yields a surprising... by psykotic on Friday January 27, 2012 @12:36AM (#3517263)
Nice trick. It works in any even base b:

    xy = b((x - b/2) + (y - b/2)) + (b - x)(b - y)
For b = 2 in particular, x - b/2 and x - b/2 are the negative 1's complements of x and y, and b - x and b - y are the 2's complements. More generally, they are the same kinds of complements generalized to base b.

Because of that symmetric relationship with complementation, I suspect there is a conceptual proof waiting to be found. By conceptual I mean something that isn't just blind formula crunching. That would get us much closer to "why".

Re:Fun with math: Dividing one by 998001 yields a surprising... by chadzawistowski on Thursday January 26, 2012 @12:52PM (#3515115)
It's a bit sneaky to say it generates all three-digit numbers when 998 clearly isn't there, but as onedognight pointed out below, the leading 1 from the 1000 which follows 999 will cause 999 to overflow into 1000, which turns the 998 into a 999.
Re:Fun with math: Dividing one by 998001 yields a surprising... by hashfold on Friday January 27, 2012 @12:12AM (#3517222)
love the math. thanks for sharing.