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 :)
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.
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:
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:
Usage: This has just the right flavor for a Project Euler problem.