1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
51–60 of 109 posts
Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#52I gotta be that guy: Why is this the first post on the front page of Hacker News? Is basic arithmetic really so fascinating to the computer people?
Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#53In high school, I was pretty fond of plugging 11^n to get rows of Pascal's triangle. It breaks down at row 5, but inserting 0's in the middle extends it (e.g. 101^n, 1001^n, 10001^n). 11^0 1 11^1 1 1 11^2 1 2 1 11^3 1 3 3 1 11^4 1 4 6 4 1
Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#54In high school, I was pretty fond of plugging 11^n to get rows of Pascal's triangle. It breaks down at row 5, but inserting 0's in the middle extends it (e.g. 101^n, 1001^n, 10001^n). 11^0 1 11^1 1 1 11^2 1 2 1 11^3 1 3 3 1 11^4 1 4 6 4 1
It actually doesn't break, you just have to do the carries as you would during normal addition. You have to read from right to left (1's place, 10's place, 100's place, and so on). So you're really just converting to base 10. 5th row: 1 5 10 10 5 1 Writing this a bit backwards, 1 * 1 + 5 * 10 + 10 * 100 + 10 * 1000 + 5 * 10000 + 1 * 100000 = 161051 = 11^5.
def pascal(n):
base = max(2, 2**n)
row = (base+1)**n
return [row/base**i % i for i in range(n+1)]
Nice, but hopelessly inefficient. :) You can also calculate a binomial coefficient the same way without any looping construct (the exponential operator does the looping for you).Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#55Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#56Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#57(a0 + (d - a0)(1/10^n)) / (1 - 1/10^n)^2
For instance the sequence 1, 4, 7, 10, 13...
(1 + (3 - 1)(1/10^2)) / (1 - 1/10^2) = 1.02 / 0.9801 = 3400/3267 = 1.004 007 010 013 016...
For any kind of recursive sequence, you can find its generating function G(x) and then substitute some integer power of 0.1 for x to generate cool decimal expansions like this.
The generating function for the Fibonacci sequence is:
G(x) = x / (1 - x - x^2)
Substituting in 0.001 gives 0.001 / 0.998999 = 0.001 001 002 003 005 008...
Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#58The pattern will break down once you get past 8192, which is 2^13. That means that the pattern continues for an impressive 52 significant figures (well, it actually breaks down on the 52nd digit, which will be a 3 instead of a 2). The reason it works is that 9998 = 10^4 - 2. You can expand as 1 / (10^n - 2) = 1/10^n * 1/(1 - 2/10^n) = 1/10^n * (1 + 2/10^n + 2^2 /10^2n + 2^3 /10^3n + ...) which gives the observed patt…
1 / (10000 - 2) = 1/10000 * 1/(1 - 2/10000)
Notice that the sum of a geometric series is: 1/(1 - x) = sum_k( x^k )
1/(1 - 2/10000) = sum_k( (2/10000)^k )
So: 1/10000 * 1/(1 - 2/10000) = 1/10000 * (1 + 2/10000 + 2^2/10000^2 + 2^3/10000^3 + ...)Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#59Reminds me of being bored in high school.
Re: 1/9998 = 0.0001 0002 0004 0008 0016 0032 0064 0128 0256..
#60Here's a generalization for any arithmetic sequence. With first term a0, difference d, and digit "padding" of n, the fraction that will result is: (a0 + (d - a0)(1/10^n)) / (1 - 1/10^n)^2 For instance the sequence 1, 4, 7, 10, 13... (1 + (3 - 1)(1/10^2)) / (1 - 1/10^2) = 1.02 / 0.9801 = 3400/3267 = 1.004 007 010 013 016... For any kind of recursive sequence, you can find its generating function G(x) and then substitu…