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) or turtle.sety(x)),[(n,(eval(eq.replace("x","(" + str(n) + ")")))) for n in range(0,100)])Tags: code, lambda, math, programming, python
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.
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)
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:
A / (C + .5 * (1 – C)) – AIn the above, A is the current age of civilization (7500 years), and C is our confidence interval (95%). A quick calculation using these values yields roughly 192 years. Ergo, we can assert with 95% confidence that civilization will last for at least the better part of two centuries. For comparison, the maximum amount of time we could (with 95% confidence) predict civilization lasting for is 292,500 years, as given by the formula
A / (.5 * (1 - C)) - AIn 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 that there is a 99.34 % chance that civilization will not end within the next 50 years, putting the likelihood somewhere between the chance you have of dying from poisoning and the chance you have of dying from a fall (statisticians, please feel free to correct me if this last figure is wrong). It should now be apparent to the reader that if I were smarter, I would have titled this post "Models Show Civilization Could End in as Little as Fifty Years". With that settled, you can get some pretty fun results with these formulas; for example, while the world wide web will probably last between half a year and 819 years, the internet will probably last between one year and 1,638 years. Apply them yourself for fun and profit!Tags: civilization, futurism, internet, math, probability, society