### Power of 2

The original text in the book:

... the first power of 2 with 8 consecutive zeroes, July 1963, ... the authors provided what the note's title suggests:

Consecutive zeros Power of 2 2 53 3 242 4 377 5 1491 6 1492 7 6801 8 14007 the first power of 2 which contains precisely eight consecutive zeros. To be explicit, taking the first case, 2^{53}= 9 007 199 254 740 992 ...

The Karst's IBM 1620 computer took 1 hour 18 mintues to find those eight consecutive zeros on 1 January 1964, ...

With Python, it is not difficult at all to do multi-precision integer arithmetic. Here is my version and it only took 46.67 seconds on my office notebook to compute up to eight consecutive zeros. My notebook (Dell Latitude D630 with Intel Core Duo CPU T7500 @ 2.20GHz) is 100.28 times faster than the IBM 1620! What would happen if I could bring this notebook back to 1960 ? Also, I am curious to know how many punch cards they required to do that calculation. My python script is only 18 lines (includes blank lines) and I am sure the factor for code base is more than 100 times. Now you get a glimpse of the advancement of both hardware and software over half a century.

$cat power2.py #! /usr/bin/python import sys,time num=1L count=1L start=time.time() while True: try: if '0'*count in str(2**num): print num, 'elapsed time: %f secs' % (time.time()-start) count+=1 num+=1 except KeyboardInterrupt: print 'Calculated till:', num sys.exit(1) $./power2.py 10 elapsed time: 0.000000 secs 53 elapsed time: 0.000000 secs 242 elapsed time: 0.015000 secs 377 elapsed time: 0.015000 secs 1491 elapsed time: 0.078000 secs 1492 elapsed time: 0.078000 secs 6801 elapsed time: 5.531000 secs 14007 elapsed time: 46.671000 secs

Labels: python

## 0 Comments:

Post a Comment

<< Home