blog | · |
schedule | · |
résumé | · |
public key | · |
contact |

You can hardly even tell that I took a course on functional programming last semester.

import turtle eq = "(x ** 2) / 1.5" map((lambda x: turtle.setx(x[0]) or turtle.sety(x[1])),[(n,(eval(eq.replace("x","(" + str(n) + ")")))) for n in range(0,100)])Tags:

Recently, I was reading about some sample interview questions used (at some point) by Google. One such question was "what are the first 10 consecutive digits of *e* that form a prime number?" Curious, I went to Wikipedia and looked up some primality tests that I could run on 10-digit prime candidates (if you'll forgive the pun) from *e*. One such test was Fermat's Primality Test, which can be used to probabilistically assess a number's primality (it fails on Carmichael numbers, *et alia*). I've written up a short python script which runs the test on the numbers 1 to 100 using computed probable primes as possible coprimes and returns all probable primes.

Download

def test(end): candidates = range(1,end+1) primes = list() for candidate in candidates: prime = True for prime in primes: if candidate % prime: test_result = ((prime ** (candidate - 1)) % candidate) print "Candidate: %s, Prime: %s, Result:%s" %(candidate,prime,test_result) if test_result != 1: prime = False break if prime: primes.append(candidate) return primes test(100)

Of course, the astute reader will notice that the above program exhaustively checks each candidate for primality for coprimality with all other probable primes, meaning that even simple trial division would be considerably faster. However, a quick modification to the program that only tested against a fixed number of random probable primes would lead to an increase in efficiency.Tags:

Although not as popular as it was during the Cold War, the notion that society is degenerating, international relations are getting worse, and humanity is on the brink of World War III still seems to be a fairly common belief. Moreover, many would have you believe that the apocalypse is due around 2012, a meteor is headed directly for earth, Yellowstone's about to blow, the next ice age is neigh, the magnetic fields of the planet are suddenly about to switch, and a long-overdue solar flare is about to wipe out all of our necessary technological systems. Still others warn that the singularity is near, robot uprising is inevitable, and grey goo will rapidly devour the world. I won't go into detail on other such scenarios. Within the group of people you know, I'd wager at least some of them think that civilization is not long for this world. This is reflected over and over again in our media, producing a plethora of post-apocalyptic films (many of which are quite good). Even if you don't subscribe to this school of thought, clearly there is still some manner of nagging concern which can be preyed upon. However, regardless of present circumstances, the idea that civilization as we know it will terminate within the next century is significantly discredited by employing the simple assumption that we are not special. More specifically, what I mean is that almost certainly we are not at the end of civilization's lifespan, and not at the very beginning (relative to what will come in the future), but instead somewhere in the middle. One can with 95% certainty say that we are currently somewhere in the middle 95% of civilization's lifetime (this is to say, supposing we were to choose 100 random points during the time that civilization will or has existed and claim that it was in the middle 95% of civilization's existence, we would be right 95% of the time (which, arguably, may not be a high enough degree of confidence)). We do have to employ a second assumption, specifically regarding how long "civilization" has been around. A nice, fairly conservative estimate would say that civilization has been around for 7500 years, which places us back at roughly the time the Egyptians were establishing themselves more formally and transitioning into a society which would later become pharaonic. Using these two assumptions, we can then evaluate the following formula in order to get the minimum amount of time civilization should last for:

In the above,A/ (C+ .5 * (1 –C)) –A

In short, civilization isn't going anywhere, at least within our lifetimes. In fact, even raising the confidence interval to 97.5% gives us 95 more years. The interval must be raised to a whopping 98.68 percent until civilization ending in as little as 50 years becomes a possibility, at which point we'd also be stating that civilization could last as long as 1.13 million years (as our interval approaches 1, the lower bound of our predicted remaining civilization lifetime nears 0 and the upper bound approaches infinity, which is to say, "Sometime between as you're reading this and never"). Another way of putting this is thatA/ (.5 * (1 -C)) -A