analytics

Monday, October 24, 2011

Looks repetitive but isn't

Suppose you start with 13. Then if the number you have is smaller than 16 double it, if it is larger than 16 divide it by 3. If it gets to exactly 16 stop. Otherwise repeat with this new number you reach. Here are the first few:

13
26.0
8.66666666667
17.3333333333
5.77777777778
11.5555555556
23.1111111111
7.7037037037
15.4074074074
30.8148148148
10.2716049383
20.5432098765
6.84773662551
13.695473251
27.3909465021
9.13031550069
18.2606310014
6.08687700046
12.1737540009


Here are the first 800 numbers of the series plotted in this 800 pixel wide image. The height of each is rounded to the nearest pixel.
(You really have to click and zoom in to be able to see the pattern)

Isn't that interesting there is a clear regularity to the pattern but I have verified that the heights of any two of these pixels are no closer than .005 apart. That means in the first 800 of the series you never repeat exactly a value. So it can't be a simple repetitive pattern.

Tuesday, October 18, 2011

A Monte Carlo for approximating e

I noticed experimentally that if you pick a random series of consecutive floating point numbers between 0 and 1 and stop when you've exceeded a sum of 1.0, you've picked on average e numbers. It always takes at least 2 numbers to add to more than 1 because each less than 1, but it could take an infinitely long time to exceed a sum of 1.0 because a floating point number can be infinitely close to 0. But in practice on average it takes a little less than three numbers, so close to e that I'm kind of assuming that it is e though I'd like to prove it.
For instance, say I picked randomly:
.248727...
.671823...
These add to only .92...
so I pick another:
.31333
Ok that exceeded 1.0 when you add all 3 so 3 goes on a list. Then I do this, say 100,000 times and average the number of tries and it came out to in one case:
2.71859
which is very close to the correct value of e:
2.71828...

I've heard many facts about e but I've never heard this particular simple one so I thought I'd post it. Here is some python source code:

import random
def trial():
    sum = 0
    counter = 0
    while sum < 1:
        sum+=random.random()
        counter+=1
    return counter
def main():
    t = 0.0
    for i in range(0, 100000):
        t+=trial()
    print t/100000
main()

Wednesday, October 5, 2011

Prime island

I made this graphic by looking at the primes smaller than 550,000. What I did was start at the center and with the number 7; I went left, up, right or down if the next prime ended with 7,1,3, or 9 respectively. Every 2200 numbers I would randomly change the color. It stayed closer to the center than I thought it would. To me I'm struck by how much it looks like geography.