Re:Fun with math: Dividing one by 998001 yields a surprising...
by onedognight on Thursday January 26, 2012 @12:18PM
(#3514957)
There's no 998 (and it's not a rounding issue)!
[ Parent
| on HN ]
Re:Fun with math: Dividing one by 998001 yields a surprising...
by onedognight on Thursday January 26, 2012 @12:32PM
(#3515025)
It's because the 1000 will end up adding one to the 999 which becomes 1000 which adds one to 998.
Re:Fun with math: Dividing one by 998001 yields a surprising...
by kghose on Thursday January 26, 2012 @12:32PM
(#3515030)
Yes, that is funky.
def long_div(x,y,N=10):
"""Given two integers x and y, return us the N digits of x/y."""
#First work out the integer part
x = int(x)
divisor = y = int(y)
quotients = [x/y]
dividend = x % y
for digit in range(N):
dividend *= 10
quotient = dividend/divisor
dividend = dividend%divisor
quotients.append(quotient)
return quotients
def pretty_print(quotients, G=3):
"""Pretty print quotients by grouping digits by 3."""
strp = ''
cnt = 1
for n in quotients[1:]:
strp += str(n)
cnt +=1
if cnt > G:
print strp
strp = ''
cnt = 1
quotients = long_div(1,998001,N=3000)
pretty_print(quotients,G=3)
Re:Fun with math: Dividing one by 998001 yields a surprising...
by tspiteri on Thursday January 26, 2012 @12:21PM
(#3514973)
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...
by joejohnson on Thursday January 26, 2012 @01:16PM
(#3515213)
Again, the 100 overflows to the 99. This makes the 99 a 100 and then that overflows again and the 98 turns to a 99.
Re:Fun with math: Dividing one by 998001 yields a surprising...
by jeffcapeshop on Thursday January 26, 2012 @12:22PM
(#3514977)
you could always do 1/99980001 - that would have a 0998
Re:Fun with math: Dividing one by 998001 yields a surprising...
by hammock on Thursday January 26, 2012 @12:50PM
(#3515106)
But it would lack a 9998.
Re:Fun with math: Dividing one by 998001 yields a surprising...
by jeffcapeshop on Thursday January 26, 2012 @12:57PM
(#3515132)
then i suppose we need 1/9999800001 !
Re:Fun with math: Dividing one by 998001 yields a surprising...
by jQueryIsAwesome on Thursday January 26, 2012 @02:04PM
(#3515445)
But it would lack... just kidding.
Another way to get the real consecutive numbers is to make a rest so we avoid that annoying increment at the end:
1/998001 - 1e-1000