Live data from Hacker News

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

iheartchaos.com

61–70 of 99 posts

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

#61
post #43

Earlier quoted context omitted.

But it would lack a 9998.

then i suppose we need 1/9999800001 !

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

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

#62
post #54

Incidentally, understanding how this works is helpful to programmers. If you know why this happens, you'll know why you can't write: double x = 0.1; and get something that works.

> you can't write ... and get something that works. That's taking things a bit far, isn't it? Sure, you can't exactly express 0.1 as a double - but you can get many things that work really well using the approximation.

What I meant to say was, "you can't expect something with a terminating representation in base 10 to always have a terminating representation in base 2". When you play with these cases in base 10, it builds intuition that can be applied to base 2 math.

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

#63
The general any-number-base-b rule here (as others have noticed in base 10^k) is that

1/(b-1)^2 = 0.0123456... (where '1', '2'.. are base b digits).

The original post is this fact in base 1000.

Proof for any base: 1/(b-1) = 1/b + 1/b^2 + 1/b^3 + .. = 0.11111.. (base b).

So 1/(b-1)^2 = 0.11111.. * (1/b + 1/b^2 + 1/b^3 + ...) = 0.012345... QED.

Richard Feynman beat us all to the punch here by noticing that 1/243 = 0.004115226337..., a fact which he wrote in a letter from a secret lab to someone in the outside world, and which put him under suspicion of sending secret messages! That gem of a fraction turns out to be a result of the above stuff as 1/243 = 111 * (1/999^2) + 4/999.

Here's a slightly more detailed explanation:

http://tylerneylon.com/b/archives/51

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

#64
post #41

... and 1/9999999800000001 = .00000000 00000001 00000002 00000003 00000004 00000005 00000006 ... 99999996 99999997 99999999 ...repeating Basically, the pattern is 1 over some number of 9s, followed by an 8, followed by the same number of 0s, followed by a 1. So, 1/81, 1/9801, 1/998001, 1/99980001, 1/9999800001, etc.

it's 9x9, 99x99, 999x999, 9999x9999,....

Now for fun figure out why they all just skip N-1. AKA 1/81 = 012345679 not 0123456789.

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

#65
I just want to repeat bdg's appreciation for the people who are explaining the actual theory, which is the interesting part. Funky results from arbitrary arithmetic is just a step short of numerology and while it's nifty in a stage magic kind of way, it's a little sad overall when you have no idea why that's the way it is.

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

#66
post #41

Earlier quoted context omitted.

it's 9x9, 99x99, 999x999, 9999x9999,....

Now for fun figure out why they all just skip N-1. AKA 1/81 = 012345679 not 0123456789.

It's because the it generates .0123456789(10), which in base 10 is actually .0123456790

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

#69

  ;Here is my version in Common Lisp
  ;Supply your own flatten function
  ;or borrow one from let-over-lambda or something
  ;http://letoverlambda.com/lol.lisp

  (defun long-div (dividend divisor depth)
    (cond
     ((> depth 0)
      (flatten (list
                (truncate (/ dividend divisor))
                (long-div (* 10 (mod dividend divisor))     
                 divisor (- depth 1)))))
     (t ())))
Post reply on HN