Live data from Hacker News

Fun with math: Dividing one by 998001 yields a surprising result

iheartchaos.com

21–30 of 99 posts

Re: Fun with math: Dividing one by 998001 yields a surprising result

#23
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 result

#24

The source with real (readable) text, without annoying animation: http://www.futilitycloset.com/2012/01/08/math-notes-76/

So we're missing 998 here in actuality ?

Yes. And 1/9801 skips 98.

Re: Fun with math: Dividing one by 998001 yields a surprising result

#25

There's no 998 (and it's not a rounding issue)! ... 995 996 997 999

And even the suggested 1/9801 for two digits produces no 98

    ... 95 96 97 99 00 01 02 ...
And extrapolating it to one digit, 1/81 gives

    0.012345679012345679...

Re: Fun with math: Dividing one by 998001 yields a surprising result

#28
post #4

This can be seen in python with (I had to dig into the docs for this, so here are the fruits of my labor :) ) import decimal decimal.getcontext().prec=1000 dec = decimal.Decimal(1)/decimal.Decimal(998001) #now doctor it up to see the numbers strdec = str(dec)[2:] #chop off the '0.' nums = zip(strdec[::3],strdec[1::3],strdec[2::3]) print nums

echo "scale=3000; 1/998001" | bc

Re: Fun with math: Dividing one by 998001 yields a surprising result

#29
post #10

The link is blocked at my workplace. I really don't understand how their filter system works.

Same here! For the category 'pornography'...

We have websense here and it too seems to block perfectly benign things with bogus reasons. This link is categorized as adult content.
Post reply on HN