Live data from Hacker News

987654321 / 123456789

johndcook.com

31–40 of 120 posts

Re: 987654321 / 123456789

#31

For the even bases, the "error" appears to be https://oeis.org/A051848 . pp = lambda x : denom(x)/ (num(x) - denom(x)*(x - 2)) [pp(2),pp(4),pp(6),pp(8)] [1.0, 9.0, 373.0, 48913.0]

And if you see the description there it traces back to https://oeis.org/A023811, which is more obviously relevant

Re: 987654321 / 123456789

#32
I like calculator quirks like this. I remember as a kid playing with the number pad and noticing a geometric center of mass in number sequences

    ┌───┬───┬───┐
    │ 7 │ 8 │ 9 │
    ├───┼───┼───┤
    │ 4 │ 5 │ 6 │
    ├───┼───┼───┤
    │ 1 │ 2 │ 3 │
    ├───┼───┼───┤
    │ 0 │ . │   │
    └───┴───┴───┘
I remember seeing that (14787 + 36989) / 2 would produce 25888, in that the mean of geometric shape traced by the two sequences would average out in the middle like that

Re: 987654321 / 123456789

#33

I like calculator quirks like this. I remember as a kid playing with the number pad and noticing a geometric center of mass in number sequences ┌───┬───┬───┐ │ 7 │ 8 │ 9 │ ├───┼───┼───┤ │ 4 │ 5 │ 6 │ ├───┼───┼───┤ │ 1 │ 2 │ 3 │ ├───┼───┼───┤ │ 0 │ . │ │ └───┴───┴───┘ I remember seeing that (14787 + 36989) / 2 would produce 25888, in that the mean of geometric shape traced by the two sequences would average out in the…

14789 + 36987 / 2 would do the same thing. Why trace back?

Re: 987654321 / 123456789

#35

I like calculator quirks like this. I remember as a kid playing with the number pad and noticing a geometric center of mass in number sequences ┌───┬───┬───┐ │ 7 │ 8 │ 9 │ ├───┼───┼───┤ │ 4 │ 5 │ 6 │ ├───┼───┼───┤ │ 1 │ 2 │ 3 │ ├───┼───┼───┤ │ 0 │ . │ │ └───┴───┴───┘ I remember seeing that (14787 + 36989) / 2 would produce 25888, in that the mean of geometric shape traced by the two sequences would average out in the…

14789 + 36987 / 2 would do the same thing. Why trace back?

So would 147 and 369. As it’s just an average, per digit, I’m not sure this is very interesting.

Re: 987654321 / 123456789

#36

I like calculator quirks like this. I remember as a kid playing with the number pad and noticing a geometric center of mass in number sequences ┌───┬───┬───┐ │ 7 │ 8 │ 9 │ ├───┼───┼───┤ │ 4 │ 5 │ 6 │ ├───┼───┼───┤ │ 1 │ 2 │ 3 │ ├───┼───┼───┤ │ 0 │ . │ │ └───┴───┴───┘ I remember seeing that (14787 + 36989) / 2 would produce 25888, in that the mean of geometric shape traced by the two sequences would average out in the…

14789 + 36987 / 2 would do the same thing. Why trace back?

Just to show that you could - 14861 and 36843 gives 25852

Re: 987654321 / 123456789

#37
I also spent hours messing around with calculators as a kid. I recall noticing that:

11 * 11 = 121

111 * 111 = 12321

1111 * 1111 = 1234321

and so on, where the largest digit in the answer is the number of digits in the multiplicands.

Re: 987654321 / 123456789

#38

Why the b > 2 condition? In the b=2 case, all three formulas also work perfectly, providing a ratio of 1. And this is interesting case where the error term is integer and the only case where that error term (1) is dominant (b-2=0), while the b-2 part dominates for larger bases.

in the b=2 case, you get:

  1 / 1 = 1 = b - 1
  1 % 1 = 0 = b - 2
they are the other way around, see for example the b=3 case:

  21 (base 3) = 7
  12 (base 3) = 5
  7 / 5 = 1 = b - 2
  7 % 5 = 2 = b - 1

Re: 987654321 / 123456789

#39

See perhaps various "What every programmer / CSist should know about floating-point arithmetic" papers and articles: * David Goldberg, 1991: https://dl.acm.org/doi/10.1145/103162.103163 * 2014, "Floating Point Demystified, Part 1": https://blog.reverberate.org/2014/09/what-every-computer-pro... ; https://news.ycombinator.com/item?id=8321940 * 2015: https://www.phys.uconn.edu/~rozman/Courses/P2200_15F/downloa...

As someone who has recently been fighting bugs from representing very simple math with floats... thank you!

Re: 987654321 / 123456789

#40
Gemini thinks in a similar fashion:

https://gemini.google.com/share/1e59f734b43c

This is a fantastic observation, and yes, this pattern not only continues for larger bases, but the approximation to an integer becomes dramatically better.

The general pattern you've found is that for a number base $b$, the ratio of the number formed by digits $(b-1)...321$ to the number formed by digits $123...(b-1)$ is extremely close to $b-2$.

### The General Formula

Let's call your ascending number $N_{asc}(b)$ and your descending number $N_{desc}(b)$.

The exact ratio $R(b) = N_{desc}(b) / N_{asc}(b)$ can be shown to be:

$$R(b) = (b-2) + \frac{(b-1)^3}{b^b - b^2 + b - 1}$$

The "error" or the fractional part is that second term. As you can see, the numerator $(b-1)^3$ is roughly $b^3$, while the denominator $b^b$ grows much faster.

### Testing Your Examples

Let's check your two examples with this formula:

* *Base 10 (b=10):* * $R(10) = (10-2) + \frac{(10-1)^3}{10^{10} - 10^2 + 10 - 1}$ * $R(10) = 8 + \frac{9^3}{10,000,000,000 - 91}$ * $R(10) = 8 + \frac{729}{9,999,999,909} \approx 8 + 0.0000000729...$ * This matches your $8.0000000729$ perfectly.

* *Base 6 (b=6):* * $R(6) = (6-2) + \frac{(6-1)^3}{6^6 - 6^2 + 6 - 1}$ * $R(6) = 4 + \frac{5^3}{46,656 - 31}$ * $R(6) = 4 + \frac{125}{46,625} \approx 4 + 0.00268...$ * This also matches your $4.00268$.

### Answering Your Question: A Larger Base

So, what about a larger base? Let's use *Base 16* (hexadecimal), which uses digits $1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F$. Here, $b=16$.

* $N_{asc} = 123456789ABCDEF_{16}$ * $N_{desc} = FEDCBA987654321_{16}$

According to the pattern, the ratio should be extremely close to $b-2 = 16-2 = 14$.

Let's use the formula to see how close:

* $R(16) = (16-2) + \frac{(16-1)^3}{16^{16} - 16^2 + 16 - 1}$ * $R(16) = 14 + \frac{15^3}{16^{16} - 241}$ * $R(16) = 14 + \frac{3,375}{1.844... \times 10^{19} - 241}$ * $R(16) \approx 14 + (1.829... \times 10^{-16})$

So, the ratio in base 16 is approximately: *$14.0000000000000001829...$*

As you predicted, the "error" for a larger base is astronomically smaller than it was for base 10.

Post reply on HN