Boa vs. Python

9:57PM, 16th February 2005

The following code took 1 minute to design and type, and about 5 minutes to run:

#!/usr/bin/python
d = 0
for i in range(0,15000):
        x = 2**i
        lead = int(str(x)[0])
        if lead == 1:
                d += 1
print float(d)/(i+1)

If it had been in C, it would've taken 5 minutes to design and type, and 1 minute to run. Some people like C's tradeoff. I, on the other hand, think Python's is the reason why it's the greatest language in modern times.

(Incidentally, I tried using Psyco, but that actually made it slower!)

(Not incidentally, the code is meant to illustrate Benford's Law, a remarkable 'law' which Mathworld describes as phenomenological. There are reasonable justifications, but it's still weird, I tells ya.)

Comments disabled for maintenance. Sorry!

← Einstein vs. Islam vs. Toilets | Home | "Bandle Bobble"? →